-
-
Notifications
You must be signed in to change notification settings - Fork 12
Issues migrating from babel-plugin-css-modules-transform with dart-sass #36
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
Comments
I’ve since found your comment here and realised this is the exact root cause of my issue. To test it, I followed your steps here to update how both my webpack and babel config specify the localIdentName (with This is without even moving away from css-modules-transform; just specifying the |
Hi @kapowaz!
Right. There were a bunch of different changes in those modules over the last few years that altered generated classnames on multiple occasions.
Correct. I believe, it does what you want.
I think, the problem is that you rely on SCSS, and for this plugin to understand SCSS you should:
|
Hi @birdofpreyru — thanks for the swift reply! That’s encouraging that this should work the way I want it to, using your more modern plugin. I’m struggling a bit with integrating the 'dist-js-build': {
presets: [
['@babel/preset-typescript', { allowNamespaces: true, allowDeclareFields: true }],
['@babel/preset-env'],
[
'@babel/preset-react',
{
runtime: 'automatic',
},
],
],
plugins: [
'@babel/plugin-proposal-class-properties',
'add-react-displayname',
[
'@dr.pogodin/react-css-modules',
{
extensions: ['.scss'],
generateScopedName: generateScopedNameFactory('kpwz-[contenthash:16]'),
preprocessCss: './src/loaders/sass-loader.js',
filetypes: {
'.scss': { syntax: 'postcss-scss' },
},
},
],
],
}, This is the output from babel:
|
I believe, you placed it well. The error reads like it tried to parse |
Yeah, that was my first guess too, so I deleted the |
Agh... then, I guess, it struggles to handle TypeScript, and you should add Babel plugin for TypeScript compilation into plain JavaScript prior to this one. |
I need to focus on something else so I’ll revisit this and try that in a little while! Thanks for the help! |
Just to give you a quick update: I’ve decided in the interim to fork css-modules-transform with updated dependencies, and I’m including your solution to handle the localIdentName differences. Longterm I’ll look into migrating to just using your package, but for now I have something that works, so thanks for the help! |
I’m migrating an older project which uses babel-plugin-css-modules-transform, and after some research I discovered you now recommend your babel-plugin-react-css-modules babel plugin as an alternative approach, as the previous packages are all abandoned/outdated.
My project setup involves React + TypeScript with SCSS. The package is published in two parts: an NPM package containing babelified JS files representing React components as CommonJS, plus a manifest file, and a set of static assets (a single minified CSS file, fonts etc.) which are published to a CDN.
The publish pipeline also runs in two parts: first it uses webpack to compile the Sass into the stylesheet published on the CDN, and then it uses babel to compile the respective JS files. As part of this process I have always used css-modules-transform to add the
var styles = { ... }
object to each component. So, assuming I start out with:I would expect to get something like this output:
All of the above has been working fine with my existing setup, and I’m using it successfully on a couple of sites (e.g. here). But a bunch of the internals were a little outdated, so I’ve started the work to gradually upgrade from e.g. webpack 4 to 5, babel 6 to 7, node 14 to 16 (so far).
However, the upgrade from node-sass to dart-sass has blocked all of this: for whatever reason the ident name generated by
generateScopedName
is different between the stylesheets emitted by webpack and thestyles = { ... }
block appended to the component by babel-plugin-css-modules-transform. I’ve exhausted all the paths I feel I can explore (for my level of knowledge of babel, at least) to try and understand why this is happening, but as best as I can tell, something about the different way that the ident name is being determined from babel-plugin-css-modules-transform compared to webpack (with css-loader, postcss-loader and sass-loader) is resulting in these different classnames.Circling back to the start, I discovered your package and it sounds like it should solve the problem I have, but I’m not able to get it to output the
var styles = { ... }
block in the published component, despite following what the readme suggests. This is the config I have in my .babelrc:For completeness, here is the equivalent section of my webpack.config.js:
What am I missing from my config to get the desired output?
The text was updated successfully, but these errors were encountered: