-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat: implement regExp option #17
base: master
Are you sure you want to change the base?
Conversation
dc23c32
to
541d280
Compare
@longlho @alexander-akait any chance of getting this considered? |
Hello, can you clarify why you need it (example)? |
hey sorry for the quick reply, hope i'm not spamming. i use it mainly through the modules: {
localIdentName: '[1]_[local]',
localIdentRegExp: /([^/]*).module.s?css/,
}, this results in names like projects with SSR use tools (eg export default function generateScopedName(name, path) {
const parsed = p.parse(path)
const filename = parsed.name.replace('.module', '')
return `${filename}__${name}`
} which i then use in plugins: [
[
'css-modules-transform',
{
generateScopedName,
extensions: ['.scss'],
processorOpts: { parser: scssParser },
},
],
], and in modules: {
getLocalIdent: (loaderContext, _localIdentName, localName) =>
generateScopedName(localName, loaderContext.resourcePath),
}, it would be nice to be able to use the regex option in both cases and avoid having to create the function to share between the contexts. |
I think we don't need it here, I think pre/post processing in css-loader should help here, regexp is limited, with function notation you will have more power and it allows to solve more problems (like this) |
So we can add new options |
I agree function notation is more powerful, but regex is considerably more concise for simple solutions. This PR doesnt really add any logic to this library, it simply exposes an already existing API from loader-utils/lib/interpolateName.js. I also figured there could be some value in having the same functionality in this library as in |
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.
Can you update docs, otherwise it will be PR only for you and me and nobody will know how to use it 😄
@alexander-akait @lohfu It would be great if this PR gets merged. I would be willing to update the docs in another PR if there's a chance to get this merged. |
@sapphi-red @madyankin I would like to make you aware of this PR. It would be great if the regExp option would be added subsequently to postcss-modules and Vite. Is there a chance that this gets added? It would allow to interpolate the component name without the Currently if your scss file in Vite is |
@pstrh I think that's possible by using the function type |
@sapphi-red Thanks for your response. You're right, we could adapt the component name with a custom function. But the problem is that this bloats the vite config. We would also have to reimplement some functionality of interpolateName or add loader-utils as dependency. Something similar was done in Create React App or Next.js. It feels kind of an overhead to reimplement this in several projects. The regExp option looks like a nice shortcut and would only expose existing functionality of interpolateName. |
this PR adds a
regExp
option that is passed toloaderUtils.interpolateName
. This option is calledlocalIdentRegExp
in webpack.