-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
How to use babel-plugin-react-css-modules without ejecting? #5113
Comments
It seems that you want too use If you want to use My recommendation would be either to eject or use react-app-rewired@next to override the portions of the webpack / babel config that you need, but be aware that this essentially "voids the warranty" provided by base CRA in terms of guaranteeing how things work. With that being said, my 95% recommendation would be to just use the built-in CRA support for CSS modules and not complicate things any further 😉 |
Thanks @transitive-bullshit , didn't know CRA used |
Correct, this version uses |
It's pretty easy to do with craco, here's a recipe to do it: https://github.com/sharegate/craco/tree/master/recipes/use-babel-plugin-react-css-modules If you want to learn more, you can find the documentation here: https://github.com/sharegate/craco/tree/master/packages/craco |
Thank you @patricklafrance, that was super helpful. FYI for all, just to be clear, babel-plugin-react-css-modules doesn't replace postcss for CSS Modules. It doesn't really do anything with processing the CSS files themselves at all. It's purely a React helper that lets you use an alternate syntax. So instead of this:
You can use this:
The alternate syntax is nice, but the main benefit for me is that with the babel plugin in place, you get error messages when you fat finger a local class name and spell it wrong. |
TL;DR; Asking for pointers on using
babel-plugin-react-css-modules
without ejecting.Hi fellow
create-react-app
users,I'm a new user to this amazing tool, having only used React on Rails projects using Webpacker (I'm mostly a Ruby developer myself). I've been following courses on several resources and I got caught up on the whole styling React thing; so far choosing CSS modules as my favorite approach.
Previously, I configured CSS modules by ejecting, but now that
create-react-app
2 is on the way I see CSS modules are coming with just an extension change. Great!However, I also saw that
babel-plugin-react-css-modules
is being favored overreact-css-modules
, in order to be able to usestyleName
and gaining all the performance benefits.So I read about having to use Babel Macros to use this without ejecting. But if I don't know how to create a plugin/macro, do I need to stick with importing styles as an object and using className?
Sources I've read: 1, 2, 3, 4, 5, 6
The text was updated successfully, but these errors were encountered: