You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simplified developer experience (no need for custom hacks or plugins)
Background
For years, Next.js developers have been looking for ways to minify CSS class names in production builds. This feature would help us to reduce the bundle sizes, especially for larger applications
Currently, developers resort to various hacks and workarounds to achieve this, as evidenced by numerous StackOverflow questions and GitHub discussions:
With the introduction of the experimental Lightning CSS loader, we have an excellent opportunity to implement this feature officially. I propose adding CSS class name minification as a built-in feature for production builds when using Lightning CSS.
Implementation Suggestion
Currently, the Lightning CSS loader uses the pattern '[name]__[hash]__[local]' for class names:
For production builds, we could change this to _[hash].
This approach is safe because CSS class names must begin with an underscore (_) or a letter (a–z), followed by any number of hyphens, underscores, letters, or numbers.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Background
For years, Next.js developers have been looking for ways to minify CSS class names in production builds. This feature would help us to reduce the bundle sizes, especially for larger applications
Currently, developers resort to various hacks and workarounds to achieve this, as evidenced by numerous StackOverflow questions and GitHub discussions:
Those solutions always try to change the configuration of the css-loader of the default next.js webpack config to inject a custom
localIdentName
:Proposal
With the introduction of the experimental Lightning CSS loader, we have an excellent opportunity to implement this feature officially. I propose adding CSS class name minification as a built-in feature for production builds when using Lightning CSS.
Implementation Suggestion
Currently, the Lightning CSS loader uses the pattern
'[name]__[hash]__[local]'
for class names:next.js/packages/next/src/build/webpack/loaders/lightningcss-loader/src/loader.ts
Lines 365 to 370 in 2a87b33
For production builds, we could change this to
_[hash]
.This approach is safe because CSS class names must begin with an underscore (_) or a letter (a–z), followed by any number of hyphens, underscores, letters, or numbers.
Beta Was this translation helpful? Give feedback.
All reactions