CSS modules classname output format #76887
Replies: 1 comment 2 replies
-
To achieve a custom CSS module class name format like the one you're aiming for (e.g., "AS2HxW" instead of "FormContainer-module__AS2HxW__FormContainer"), you need to modify the localIdentName in your css-loader configuration, which controls how class names are generated in CSS Modules. You're on the right track with extending the Webpack configuration in next.config.js. However, it looks like you're not using the correct format for the localIdentName in css-loader. You should be using localIdentName: "[local]__[hash]" to get the hash alone, and not the file or class name. Here’s how you can modify your next.config.js to achieve this:
Explanation:localIdentName: "[local]__[hash:base64:5]": CSS Modules are activated by default when you use the next setup with PostCSS, so you only need to modify the localIdentName within the css-loader options. The base64 hash length (in this example 5) can be changed depending on how long you want your hash to be. If possible, could you kindly validate my answer when you have a moment? I really appreciate your attention, and I hope I was able to help! |
Beta Was this translation helpful? Give feedback.
-
Summary
I'm looking to modify the format of the css scope name, for example this is what i'm currently getting "FormContainer-module__AS2HxW__FormContainer" and say for example i just want it as hash "AS2HxW" (just an example)
Additional information
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions