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/

    1. const lessModuleRegex = /\.module\.less$/;
    2. const localIdentName = '[local]-[hash:base64:5]';
    3. plugins: [
    4. {
    5. plugin: CracoLessPlugin,
    6. options: {
    7. modifyLessRule(lessRule, context) {
    8. return {
    9. ...lessRule,
    10. ...{
    11. test: lessModuleRegex, // /\.module\.less$/,
    12. exclude: undefined, // /node_modules|antd\.css/
    13. },
    14. };
    15. },
    16. // Passing an options object to configure the css-loaders
    17. cssLoaderOptions: {
    18. modules: {
    19. // 必须保持和 babel-plugin-react-css-modules 一致的命名
    20. localIdentName,
    21. },
    22. },
    23. },
    24. },
    25. ]