Closed artemtam closed 3 years ago
It seems this is rollup-plugin-postcss
issue. https://github.com/egoist/rollup-plugin-postcss/issues/281
Thanks for the pointer to that issue.
Just to clarify - the .local-no-module-class
is coming from index.css
?
I think it may be possible to work around this using :global{}
in the interim:
:global {
@import url('./index.css');
}
In terms of a longer term fix: we should be able to use the undocumented options.modules.getJSON()
option in rollup-plugin-postcss:
Another approach would be to generate a regex for globalModulePaths
that matches everything except *.module.css
.
Yes, .local-no-module-class
comes from index.css
.
The workaround is suitable only for local files – we can't adjust third-party dependencies. Actually, I faced this issue initially with third-party CSS.
IMO, the bug is pretty critical – it appeared in 0.12 and could break lots of projects. Clearly, rollup-plugin-postcss
behavior is confusing, though it probably it makes sense to just not pass any options to the plugin, so the default class name generation algorithm will be used.
Ah, I am mistaken about the workaround. It probably should work, thank you.
Duplicate of #617 ;)
@katywings the title is confusing, so I didn't get it's the same issue :(
I can't believe this is still open, so css modules is still the only acceptable form of css if I use microbundle? @artemtam @katywings I come across this when using create-react-library (which use microbundle)
@FateRiddle yupp :/, and we are not alone: https://github.com/egoist/rollup-plugin-postcss/issues/281#issuecomment-649499833
@FateRiddle This is an upstream bug in rollup-plugin-postcss
. Nothing we can do about that in here microbundle
.
EDIT: On second thought: What if we disable CSS modules and only enable it for .module.css
files? If the docs are to be believed they have an autoModule flag that we should use instead.
@marvinhagemeister it is not about autoModules
, the issue is in this line: https://github.com/egoist/rollup-plugin-postcss/blob/9489ecaabbf9a4726f67deb0095914d624e9d462/src/postcss-loader.js#L74
Basically, in case you pass anything in modules
, all files are treated as CSS Modules. As far as I understand, Microbundle passes class names format via modules
property. So it seems if Microbundle just doesn't pass it and sticks with the default names provided by rollup-plugin-postcss
, the issue will be resolved.
@artemtam yup, that's what I was referring to. Sounds like an easy enough fix 🎉
This problem exists for me. When will the fix be made?
@olgenn right above your comment are links to two PRs filed upstream to get this resolved. We will update microbundle once a fix is merged upstream.
It should be fixed when https://github.com/developit/microbundle/pull/680 gets merged in.
Hi @wardpeet! #680 is closed, so the issue is fixed?
Not yet, will be fixed when https://github.com/developit/microbundle/pull/738 is merged.
Hi Sorry, is this issue fixed ?
Today I created a library using "create-react-library" and I'm having this error, is there any workaround ?
I tried the
:global { @import url('./index.css'); }
mentioned above, but not even sure where to put that
Thank you
The fix will be published in 0.13.
Is there any additional step needed for scss
files? This is still not fixed for me I am using the CRL fork though
@geocine Do you have a quick example repo showing what you try to do? 🙂
still doesn't work if you're changing the css-modules naming convention (e.g. --css-modules '_[name]__[local]__[hash:base64:5]'
changes all css names, not just modularized css)
still doesnt work. styles.sass is still using css modules. only using --css-modules false works.
the problem is I want to support both by distctioning the name containing "module". i saw postcss bug was fixed.
any workaround?
still doesnt work. styles.sass is still using css modules. only using --css-modules false works.
the problem is I want to support both by distctioning the name containing "module". i saw postcss bug was fixed.
any workaround?
the best solution for me was to get rid of microbundle. it's been two years so this is obviously not going to be fixed.
the best solution for me was to get rid of microbundle. it's been two years so this is obviously not going to be fixed.
That's the proper solution. We mainly wrote microbundle
to make it easier to ship JS libraries like Preact itself. It was never intended to be used for full blown applications bundling with multiple asset types etc. That's not microbundle's use case.
Regardless
--css-modules
flag, it is impossible to use CSS and CSS Modules in the same project. It seems thatnull
option works incorrectly and Rollup treats all CSS files as modules.To reproduce, you could try to build this simple example:
Building with
microbundle ./index.jsx
makes the followingindex.css
file:However, the expected result is: