According to a tweet by Dan Abramov, CSS modules support is there in create-react-app (CRA). One just needs to give extension of module.css
to his stylesheets to enable the feature, but this is not working with me. I am having version 1.1.4 of react-scripts
. How can I enable css modules with CRA? Thanks
相关问题
- How to toggle on Order in ReactJS
- Refreshing page gives Cannot GET /page_url in reac
- Adding a timeout to a render function in ReactJS
- React Native Inline style for multiple Text in sin
- Issue with React.PropTypes.func.isRequired
相关文章
- Why would we use useEffect without a dependency ar
- Is it possible to get ref of props.children?
- Stateless function components cannot be given refs
- React testing library: Test attribute / prop
- React/JestJS/Enzyme: How to test for ref function?
- Material-UI [v0.x] RaisedButton on hover styles
- Remove expo from react native
- ReactJS toLowerCase is not a function
You do not need to eject.
Create-React-App supports css modules right out of the box as of version 2, which is now stable.
Upgrade to v2 (
react-scripts@latest
) by runningyarn upgrade react-scripts@latest
.You just have to create a file with the extension
.module.css
For example:
Then you can use it like so:
You need to eject create-react-app and then in config files for webpack you add these 2 lines
And to use it load css to Component you wan't (i keed component and it's css in same folder)
...
inside SomeComponentStyle.css