Github cssModuels文档 https://github.com/css-modules/css-modules
关键在 modifyLessRule 和 cssLoderOptions 两个选项
- modifyLessRule 修改 less-loader 规则,
- cssLoaderOptions 启动 css-modules 并配置生成的 classname 格式
https://github.com/umijs/umi/issues/1417
cssModules实战 https://github.com/camsong/blog/issues/5
https://juanha.github.io/2017/01/10/react-css-modules/
const lessModuleRegex = /\.module\.less$/;
const localIdentName = '[local]-[hash:base64:5]';
plugins: [
{
plugin: CracoLessPlugin,
options: {
modifyLessRule(lessRule, context) {
return {
...lessRule,
...{
test: lessModuleRegex, // /\.module\.less$/,
exclude: undefined, // /node_modules|antd\.css/
},
};
},
// Passing an options object to configure the css-loaders
cssLoaderOptions: {
modules: {
// 必须保持和 babel-plugin-react-css-modules 一致的命名
localIdentName,
},
},
},
},
]