react - using CSS Modules in a Nrwl NX workspace
See original GitHub issueI run version 8.4.12 of nx
I would like use css modules in a react app
In a recent react project, created with “create-react-app”, I am able to use css modules.
e.g.
import classes from './MyComponent.module.css';
and the usage:
<div className={classes.my-css-class}> </div>
How is this possible with nx?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:23 (6 by maintainers)
Top Results From Across the Web
How can I use CSS Modules in a Nrwl NX workspace?
I'm refactoring an old React/Webpack project to Nrwl's NX monorepo solution. In that project css modules are used.
Read more >@nrwl/react:library | Nx
Create a React Library for an Nx workspace. ... nx g @nrwl/react:library . ... the stylesheet is generated using global CSS instead of...
Read more >Add Styling to a React app inside an Nx workspace | egghead.io
In this lesson we're going to explore how to add some more styling to our React app inside the Nx workspace. We're exploring...
Read more >Using Nx Workspace generators to scaffold new blog posts
This week we'll continue by looking at how to leverage Nx Workspace generators to ... CSS file for the React component, especially if...
Read more >How to use custom webpack configuration in an Nx project?
How to customize webpack config for an NX project? · Go to the workspace.json file · Find the project you wish to edit...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Any update about lib support SCSS modules?
Hi @maku
We don’t currently support CSS modules but we can look at extending our builder for it.
The workaround right now is to provide your own custom webpack to the web builder.
Look in your
workspace.jsonfile for your app and you should find abuildentry underarchitect.You need to switch
webpackConfigwith your own, such as"./apps/demo/webpack.config.js". Please changedemoto your actual app name.Now, you need to provide the config function like this:
https://gist.github.com/jaysoo/431828f47e5202d3e4afc6c34fdac2c0
This function modifies the webpack config by adding a rule to handle
.module.cssfiles, as well as exclude these files from other rules.There will be more configuration beyond that, especially for production builds, postcss (if you use that), etc.