# Migrating to the new CSS options This guide shows how to migrate your existing Rsbuild CSS configuration to the new `css` options. ## Migrate `output.injectStyles: true` For web builds, replace `output.injectStyles: true` with `css.exportType: 'style'`. ```diff title="rsbuild.config.ts" export default { - output: { - injectStyles: true, + css: { + exportType: 'style', }, }; ``` ## Replace `output.cssModules.namedExport` Rename `output.cssModules.namedExport` to `css.modules.namedExports`. Keep `true` for named exports only. ```diff title="rsbuild.config.ts" export default { - output: { - cssModules: { - namedExport: true, + css: { + modules: { + namedExports: true, }, }, }; ``` ## Replace `output.cssModules.localIdentName` Move your class name template to `css.modules.localIdentName`. If it includes a hash, generated class names can change even with the same template. ```diff title="rsbuild.config.ts" export default { - output: { - cssModules: { + css: { + modules: { localIdentName: 'app-[local]', }, }, }; ``` ## Migrate `output.cssModules.exportLocalsConvention` Move `output.cssModules.exportLocalsConvention` to `css.modules.exportsConvention` and update the option value. ```diff title="rsbuild.config.ts" export default { - output: { - cssModules: { - exportLocalsConvention: 'camelCaseOnly', + css: { + modules: { + exportsConvention: 'camel-case-only', }, }, }; ``` | Old value | New value | JavaScript keys for `.foo-bar` | | ----------------------- | ------------------------ | --------------------------------------- | | `'asIs'` | `'as-is'` | `styles['foo-bar']` | | `'camelCase'` (default) | `'camel-case'` (default) | `styles['foo-bar']` and `styles.fooBar` | | `'camelCaseOnly'` | `'camel-case-only'` | `styles.fooBar` | ### Class names containing digits When migrating either camel-case setting, update any `styles.foo2Bar` references for the CSS class `.foo2bar`. ```diff title="index.js" import styles from './style.module.css'; -document.body.className = styles.foo2Bar; +document.body.className = styles.foo2bar; ``` ### Migrating `'dashes'` and `'dashesOnly'` For a class named `.foo-bar`, these mappings preserve the existing JavaScript keys. | Old value | New value | | -------------- | ------------------- | | `'dashes'` | `'camel-case'` | | `'dashesOnly'` | `'camel-case-only'` | If you keep `'dashes'` or rename `'dashesOnly'` to `'dashes-only'`, `.foo-bar` no longer exports the `fooBar` key. Update any code that reads it. ```diff title="index.js" import styles from './style.module.css'; -document.body.className = styles.fooBar; +document.body.className = styles['foo-bar']; ``` For an existing camel-case class such as `.navItem`, `'dashes'` adds the key `styles['nav-item']`. Switching from `'dashesOnly'` to `'dashes-only'` requires changing `styles.navItem` to `styles['nav-item']`. ## Migrate `output.cssModules.mode` Move `output.cssModules.mode` to `css.modules.mode` and keep the same value for `'local'`, `'global'`, or `'pure'`. ```diff title="rsbuild.config.ts" export default { - output: { - cssModules: { + css: { + modules: { mode: 'pure', }, }, }; ``` The legacy `'icss'` value and per-file mode callback have no direct equivalent in `css.modules.mode`.