Open BenMorel opened 5 years ago
Hi @BenMorel,
configure the loader to use CSS modules or not by default, and allow overriding on import by using a suffix such as file.css?global or file.css?module
Encore should actually already support this by default using ?module
:
@Lyrkan Indeed this works out of the box, thanks a lot! 🥇
I guess this is the recommended way to use CSS modules with webpack-encore then; is this documented anywhere?
is this documented anywhere?
I dont think it is... when we added support for that in #508 it was mainly for Vue.js users since it was the documented way to opt-in for CSS modules: https://vue-loader.vuejs.org/guide/css-modules.html#opt-in-usage (using <style module>
for instance).
There is a really small mention of it there: https://symfony.com/doc/current/frontend/encore/vuejs.html#using-scoped-styles
But maybe it deserves a better exposure for non-Vue.js projects.
But maybe it deserves a better exposure for non-Vue.js projects
Definitely, this is a killer feature that a lot of projects would benefit from, I guess. I'm personally using it to style React components.
Should I leave this issue open, until the docs are updated?
Should I leave this issue open, until the docs are updated?
👍
Hi, not sure if it can help, but I had some similar issue (?module not working with Jest) and fixed it with something like that (with Webpack Encore) :
.configureCssLoader(options => { options.modules = { auto: /.module.\w+$/i }}) And now you can create a file with '.module.scss' suffix, and you can import it in a ts file.
Hope that's work and help
Hi, not sure if it can help, but I had some similar issue (?module not working with Jest) and fixed it with something like that (with Webpack Encore) :
.configureCssLoader(options => { options.modules = { auto: /.module.\w+$/i }}) And now you can create a file with '.module.scss' suffix, and you can import it in a ts file.
Hope that's work and help
I was close to broke my computer before finding your answer. Thanks by a lot
Yeaaah, I'm glad I could help someone with that. That was a lot of pain/despair for me too !
Yeaaah, I'm glad I could help someone with that. That was a lot of pain/despair for me too !
Just come across this 2 years later - saved me an awful lot of head scratching - thank you!
Yeaaah, I'm glad I could help someone with that. That was a lot of pain/despair for me too !
Just come across this 2 years later - saved me an awful lot of head scratching - thank you!
Glad this helped !
I'd like to use CSS modules by default for all my SCSS code, but disable it for Bootstrap SCSS files.
Right now I have this setup:
It works fine, but if I import Bootstrap SCSS files in my project:
It gets compiled to something like:
i.e. Bootstrap gets modularized, instead of being considered global by default.
There have been extensive discussions about how to tackle this problem. A few suggestions seem to stand out of the crowd:
.module.css
or.module.scss
node_modules
file.css?global
orfile.css?module
Is there a way to configure either of these behaviours with webpack-encore right now, and is one of them officially recommended?
The various suggestions in the above thread seem hard to implement with Encore at the moment, and I'd like to avoid having to configure webpack manually if I can.