react-app-rewired: css module with babel-plugin-import not work.
Hello,i used css module with babel-plugin-import,but it does’t work. either css module or babel-plugin-import work. here’s my config-overrides file:
const { injectBabelPlugin,getLoader } = require('react-app-rewired')
const rewireLess = require('react-app-rewire-less')
const cssLoaderMatcher = function(rule) {
return rule.loader && rule.loader.indexOf(`css-loader`) != -1;
}
module.exports = function override(config, env) {
let l = getLoader(config.module.rules,cssLoaderMatcher);
l.options = {
modules: true,
importLoaders: 1,
localIdentName: '[local]___[hash:base64:5]'
}
config = injectBabelPlugin(['import', { libraryName: 'antd', style: true }], config);
config = rewireLess(config, env, {
modifyVars: { "@primary-color": "#1DA57A" },
})
return config;
};
https://ant.design/docs/react/use-with-create-react-app i wanna use this React Ui library with css module , how should i do it
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 18 (1 by maintainers)
@WhatAKitty i forked repo from @codebandits and put the code above in and tweaked it a bit:
https://github.com/andriijas/react-app-rewire-less-modules
I also added less options to less module loader which makes it possible to use theme variables in components (primary colors etc). Check example repo: https://github.com/andriijas/create-react-app-playground/
Check these files: Footer.less Footer.js theme.less config-overrides.js .env
Big thanks @WhatAKitty and @codebandits - saved me a lot of time
I changed it a little, the difference is that all css and less from node_modules , for example antd will load normally and all css and less loaded from src/ will be treated as css modules. No need for foo.module.less files.
Note the
libraryDirectory: "es"
in babel import for antd, will use node_modules/antd/es instead of node_modules/antd/libI’ve done something like this to get it working in my project
and