react-css-modules | Seamless mapping of class names | Frontend Framework library
kandi X-RAY | react-css-modules Summary
kandi X-RAY | react-css-modules Summary
React CSS Modules implement automatic mapping of CSS modules. Every CSS class is assigned a local-scoped identifier with a global unique name. CSS Modules enable a modular and reusable CSS!. ️️️ DEPRECATION NOTICE ️️️ If you are considering to use react-css-modules, evaluate if babel-plugin-react-css-modules covers your use case. babel-plugin-react-css-modules is a lightweight alternative of react-css-modules. babel-plugin-react-css-modules is not a drop-in replacement and does not cover all the use cases of react-css-modules. However, it has a lot smaller performance overhead (0-10% vs +50%; see Performance) and a lot smaller size footprint (less than 2kb vs +17kb). It is easy to get started! See the demo
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of react-css-modules
react-css-modules Key Features
react-css-modules Examples and Code Snippets
Community Discussions
Trending Discussions on react-css-modules
QUESTION
I'm using babel-plugin-react-css-modules
and need to pass classes via props to React components, as such:
ANSWER
Answered 2021-Aug-31 at 07:44I found a solution to this. By passing in the attributeNames
option when configuring the plugin, I could specify the names of props that I want to be transformed, and what I want them to be transformed to.
QUESTION
I trying to setup own simple webpack config with css-modules. And problem is that I getting different hashes by css-loader and babel css modules plugin in css classes names.
...ANSWER
Answered 2021-May-29 at 13:43It seems this issue is yet resolved yet which is open here. Basically you can use this forked package @dr.pogodin/babel-plugin-react-css-modules
to fix the compatibility with css-loader
in case of generating the name.
The idea would look like:
QUESTION
I want to upgrade to webpack 5. I've followed the official guide, upgraded all critical libraries (react17, babel, loaders, etc.). When launching the app, it crashes with 23 errors. 21 of them come from @babel/runtime/helpers
.
A typical error looks like this:
ERROR in ../../node_modules/@babel/runtime/helpers/esm/createSuper.js 1:0-46 Module not found: Error: Can't resolve './getPrototypeOf' in '/Users/myName/Desktop/myapp/node_modules/@babel/runtime/helpers/esm'
The two other errors are:
Module not found: Error: Can't resolve 'url-loader' ERROR in FaviconsWebpackPlugin - This FaviconsWebpackPlugin version is not compatible with your current HtmlWebpackPlugin version. Please upgrade to HtmlWebpackPlugin >= 5 OR downgrade to FaviconsWebpackPlugin 2.x
Note: My html-webpack-plugin version is above 5 and favicons-webpack-plugin is the latest version as well...
Anyway, here is my webpack file:
...ANSWER
Answered 2021-Mar-01 at 06:53releted to https://github.com/babel/babel/issues/8462, runtime issues can be solved by upgrading the @babel/runtime pkg version above 7.12.0
QUESTION
ANSWER
Answered 2021-Jan-20 at 15:11QUESTION
Trying to setup a react-app with all latest versions.
Trying to run storybook with sass file imported will result in below error. Trying to run without importing the styles, storybook works.
The same code works correctly when its run as npm start run
with no warnings and errors.
I have configured css modules using @dr.pogodin/babel-plugin-react-css-modules with sass, webpack 5, react 17 and with latest packages.
...ANSWER
Answered 2020-Dec-27 at 12:24I don't know what you have done with your configuration but you would define the config things inside .storybook/main.js
. And for global style css is supposed to be included in preview.js
file.
In short, you have to do the few things:
- Remove your
.storybook/config.js
and add.storybook/main.js
with following content:
QUESTION
Currently I am using webpack 5, react 17 and @dr.pogodin/babel-plugin-react-css-modules and all other latest packages.
I am excluding the sass/css files in assets/stylesheets which is being treated as global and using those classes inside className
Styles won't be applied changing localIdentName to something else. Tried getLocalIdent but no use.
So how to change the localIdentName ?
package.json
...ANSWER
Answered 2020-Dec-27 at 09:19Sounds like I forgot to tell you babel-plugin-react-css-modules
has an option to configure the scoped name too which is called generateScopedName
.
As long as you configured this as same as css-loader
, it should work then:
.babelrc
QUESTION
I am trying to setup a react app with latest versions. React 17, Webpack 5 and other modules.
I need css modules with styleName concept by using babel-plugin-react-css-modules
Trying to run the code shows the output but no styles are applied.
package.json
...ANSWER
Answered 2020-Dec-25 at 08:26That's interesting issue which requires us to do a few more things to make it work as following:
babel-plugin-react-css-modules
isn't working properly withcss-loader
in case of generating the name. But luckily we have a work around by using a temporary fix of someone@dr.pogodin/babel-plugin-react-css-modules
. So just install needed packages:
QUESTION
I'm trying to implement css modules in my typescript react project, but still can't get the css file imported:
- I use css-modules-typescript-loader to create .css.d.ts to assert typing
- I use @dr.pogodin/react-css-modules to be able to use css modules ("styleName") in react. It'll generate some hash for the css property like the "src-containers-___App__background___2WjSL" in the image above
Here are the files regarding the App and css:
App.tsx:
...ANSWER
Answered 2020-Nov-06 at 18:31The problem here is the generated hash name between babel-plugin-react-css-modules
vs css-loader
are now different in pattern.
In order to fix this, since babel-plugin-react-css-modules
is now using this pattern [path]___[name]__[local]___[hash:base64:5]
by default, you just fix by configure css-loader
using the same pattern as following:
QUESTION
I want to use babel-plugin-react-css-modules
to create unique class names, so I did a PoC: I ejected create-ract-app, then I add babel-plugin-react-css-modules
to plugins in package.json:
ANSWER
Answered 2020-Jan-18 at 19:46Rant: One of the many reasons I'm against the create-react-app
(CRA) is because of how inflexible it can be when it comes to customization. If you're looking to include features, I'd recommend creating your own webpack configuration. Why? You'll become more familiar with Webpack, how to configure it, how to work within its limits, and how to add/change/adjust packages to your needs.
That said, the CRA comes preconfigured with both global and local (module) CSS imports and it conflicts with babel-plugin-react-css-modules
(BPRCM). The CRA expects .css
files without module.css
to be normal global imports. Meanwhile, BPRCM expects .css
files to be local imports. Not only is that a conflict, but the localIdentName
s are mismatched. By default, CRA looks for App.module.css
where module.css
specifies it's a modulated import, like so: import { App } from "./App.module.css";
. As such it assigns localIdentNames as [file/folder]_[local]_[hash]
as mentioned here, here and within an ejected config/webpack.config.js
(Lines 432-456 -- it utilizes the react-dev-utils/getCSSModuleLocalIdent
package).
In order to resolve these conflicts, you'll need to establish a localIdentName
(by default BPCRM uses this generateScopedName
: [path]___[name]__[local]___[hash:base64:5] (4th option in the table), so I'll be using it for my example below), then you'll need to add BPRCM to the webpack.config.js
under babel-loader
because the CRA doesn't look for a babel configuration, then you'll have to remove the CSS module imports rule, and lastly, you'll need to add some options to their global CSS rule to make it local and utilize the localIdentName
.
Here's a working example: https://github.com/mattcarlotta/cra-css-modules
To utilize the repo above:
- open a terminal window on the
~/Desktop
and clone the repo:git clone git@github.com:mattcarlotta/cra-css-modules.git
- cd into the
cra-css-modules
folder and typeyarn install
ornpm install
- type
yarn start
ornpm start
to run the example
What I changed:
- Declared a localIdentName to match BPRCM's default scoped class name (you can change this name to whatever you like and it'll still work with the example repo above).
- Added BPRCM to the
babel-loader
rule. - Added a modules configuration to switch the global CSS rule to a local CSS rule
- Removed the local modules CSS rule.
- Changed all
classNames
tostyleName
in the App.js file.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install react-css-modules
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page