-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSS Modules localIdentName cleanup #3965
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -306,7 +306,7 @@ module.exports = { | |
minimize: true, | ||
sourceMap: shouldUseSourceMap, | ||
modules: true, | ||
localIdentName: '[path]__[name]___[local]', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per suggestions from Dan, you can try something along these lines for both dev and prod. {
loader: require.resolve('css-loader'),
options: {
importLoaders: 1,
modules: true,
getLocalIdent: (context, localIdentName, localName, options) => {
// Use the filename or folder name, based on some uses the index.js / index.module.css project style
const fileNameOrFolder = context.resourcePath.endsWith('index.module.css') ? '[folder]' : '[name]'
// Create a hash based on a the file location and class name. Will be unique across a project, and close to globally unique.
const hash = loaderUtils.getHashDigest(context.resourcePath + localName, 'md5', 'base64', 5)
// Use loaderUtils to find the file or folder name
const className = loaderUtils.interpolateName(context, fileNameOrFolder + '_' + localName + '__' + hash , options)
// remove the .module that appears in every classname when based on the file.
return className.replace('.module_', '_')
},
minimize: true,
sourceMap: shouldUseSourceMap,
},
}, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also "hide" this function into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ro-savage Thank you so much. Was on my todo list to use |
||
localIdentName: '[hash:base64:5]', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still deterministic, it is just smaller and no longer useful for a human to read/look at. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes this is exactly the point. Developers should not use those values. And it is nice that they are small. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sometimes you have to overwrite some styles but you have no access to this this component (eg component library), so the only way that you have - is to use this Will be better to have ability to configure this |
||
}, | ||
}, | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would allow clashes in names. Its unlikely, but could happen, so add it as a possibility?
Having difference between the final output and dev, can also cause friction as it makes it much harder to look at the production site and find the issue when running in dev mode because all your class names are unrelated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree I would leave it as is