-
Notifications
You must be signed in to change notification settings - Fork 193
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
[Feature Request] Support generateScopedName
config like postcss-modules
#156
Comments
What's the usecase for this? What are you looking to customize and why? |
@devongovett my usecase is using parcel-css in a legacy frontend project, which has some E2E testing cases using class name as selector of element, e.g.: cy.get('[class^="some-class-name"]').click()... in the latest version of parcel-css, the class name will be |
btw, I think change position of [hash] is really a breaking change that should be highlighted in release note |
Hmm I think the point of css modules is to avoid relying on specific class names, and to keep them locally scoped. The hash position change was necessary to accommodate css grid line names, which the browser may automatically postfix in some cases. I'll have to think about this more. |
how about give developer a chance to choose the hash position? |
Well, if it's not at the start then css grid will be broken... |
no css grid in my project 😂 |
@devongovett I have an interesting use case for custom https://github.com/utilitycss/atomic is a framework based on postCSS that relies on postcss-modules hevily using composition and relying on a "stable" hashing strategy that guarantees that a hash will only change if the final css rule itself is changed (by default it will change in a number of other cases e.g. adding composes, changing something in the rest of the file, adding a comment, etc...) I have a long term dream to migrate the project to rust, but doubt it would be feasible without a plugin system like in postcss. Said that this project may be a good starting point (not sure if among the goals there is the possibility to include a plugin system). Just wanted to contribute my use case for a custom here you can see the Also custom hash functions can have some use cases: https://github.com/utilitycss/atomic/blob/master/src/postcss/atomic-css-modules/hashFunction.ts The most important here is to be able to choose the length (depending on the amount of classess you foresee to use you can use more or less characters while keeping the risk of collisions extremely low) |
I think we could provide limited support for this. I wouldn't want to support a callback function where you can do any arbitrary computation in JavaScript because that will slow things down a lot. But we could probably support a pattern syntax like this: {
"cssModules": {
"pattern": "prefix-[name]-[hash]"
}
} For CSS grid, we'd need to enforce that the hash is added at the start - or rather, that the pattern ends with "[name]". |
Working on support for it here if anyone has feedback: #180 |
I think rather than trying to reproduce the same logic it would be better to just not use let myHash = computeHash(filename);
parcelCss.transform({
// ...
cssModules: {
pattern: `[local]-${myHash}`
}
}) |
Ah of course. I suppose I was thinking that the hash created by rust would be faster, but that may not be an issue. |
e.g.
generateScopedName: "[name]__[local]___[hash]"
https://github.com/madyankin/postcss-modules#generating-scoped-names
The text was updated successfully, but these errors were encountered: