Repository navigation
Support exportLocalsConvention for CSS Modules in Turbopack
#91838
johndalvik
started this conversation in
Ideas
Replies: 1 comment
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Goals
css-loadermodules.exportLocalsConventionoptionNon-Goals
asIsremains the default for backwards compatibilitycss-loadercss-loaderalso accepts a function, but string values cover all practical use cases)Background
Webpack's
css-loaderhas supportedmodules.exportLocalsConventionfor years. Many projects — especially those using SCSS — write kebab-case in stylesheets and camelCase in JavaScript:Turbopack hardcodes exports as-is with no configuration option, which blocks adoption for any project relying on this pattern.
Current alternatives:
styles["main-content"]) — poor DX, no autocompleteThe webpack implementation already exists in the Next.js repo:
packages/next/src/build/webpack/loaders/lightningcss-loader/src/codegen.ts— convention switchpackages/next/src/build/webpack/loaders/css-loader/src/camelcase.ts— camelCase transformpackages/next/src/build/webpack/loaders/css-loader/src/utils.ts— dashesCamelCase transformProposal
Add a
turbopack.cssModules.exportLocalsConventionoption tonext.config.js:Supporting all 5 conventions matching webpack's
css-loader:.main-contentexportsasIs(default)styles["main-content"]camelCasestyles["main-content"]+styles.mainContentcamelCaseOnlystyles.mainContentdashesstyles["main-content"]+styles.mainContentdashesOnlystyles.mainContentI have a working implementation ready as a PR. Changes span:
CssModuleExportConventionenum and transform functions inturbopack-css, threaded throughturbopackandnext-corecratesconfig-shared.ts, zod schema inconfig-schema.tscamelCaseOnlyin Turbopackturbopack.mdxwith CSS Modules sectionAll reactions