-
-
Notifications
You must be signed in to change notification settings - Fork 162
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
Instructions to switch from react-css-modules #108
Comments
I should have been more clear about what's not working. The CSS stylesheets aren't being used when rendered. The What am I missing from my configuration? |
Assuming that you are not using |
@gajus Doesn't HTML Webpack Plugin cover that? It wasn't a problem when I was using React CSS Modules or CSS Modules, only when I tried to switch to babel-plugin. |
I followed the configuration in this tutorial, which seems quite comprehensive: https://clever.ly/blog/2017/06/16/css-modules-in-react/ I added a
With my setup matching that one and, as far as I can tell, the demos in this project, the stylesheets aren't being fetched. This is a screen shot that should have basic styling (looks pretty much like the initial create react app does). You can see that the classes are being generated but not the styles. Is there a specific reason that you don't recommend using I don't see a link to the CSS in the demo HTML file. I don't think this is really an option for me anyway, as I'm building a component library package to use in a separate application. |
@apennell I was using your example as a hint on how to configure
But the default |
I'm having the same issue — my generated styles aren't linked anywhere. @apennell, did you ever figure out your issue? [edit/solved] Turns out the styles were being injected into the head of the document, but I hadn't configured css-loader fully. My working Webpack 3 config looks like: {
test: /\.css$/,
exclude: /node_modules/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
// This matches the babel plugin's setting
localIdentName: '[path]___[name]__[local]___[hash:base64:5]',
},
},
],
}, |
In my experience, it's important that babel-plugin-react-css modules comes first in the list of plugins. I noticed a comment that I left for myself in the past in my .babelrc. This has been working great for months when using .js/.jsx and babel (don't have it working with typescript): // the react-css-modules plugin should be first in the list of plugins |
Thanks for the input and potential fixes @angelikatyborska @robwierzbowski @domehead100! I wasn't able to get it working back when I was building this and, if I recall correctly, I ended up going back to just using the basic css-modules. I'm no longer working at the company I was using this for so I can't try these fixes out now, but I'll revisit this thread if I get a chance to implement css modules at my new company! 😁 |
@robwierzbowski Thanks, it looks like the |
Adding documentation as requested in gajus#108 (comment)
Adding documentation as requested in #108 (comment)
If anyone is looking to use this in a
|
It would be great if there was a section with the steps required to switch from using react-css-modules to babel-plugin-css-modules, since this is now recommended over that package.
I built out an app using create-react-app and successfully implemented react-css-modules. There's a note in the react-css-modules Readme about using babel-plugin-react-css-modules instead, but it wasn't clear that it's no longer maintained or recommended by @gajus so I went with the original. After running into problems with Jest testing, I learned in the issue addressing my problem that @gajus doesn't recommend using it, so I'm trying to switch to this one.
I figured that I could just change the setup of my components that worked with react-css-modules, but it doesn't work.
My React components:
To enable react-css-modules in my create-react-app, I modified my webpack.config to have:
I've looked at several issues related to this, including issue #5 and issue #82 , and it looks like babel settings need to be updated, but I've been unsuccessful in my attempts so far.
The text was updated successfully, but these errors were encountered: