1. 安装依赖

    npm  i react-app-rewired customize-cra babel-plugin-import less less-loader -D
  2. 修改package.json

    ....
        "scripts": {
            "start": "react-app-rewired start",
            "build": "react-app-rewired build",
            "test": "react-app-rewired test",
            "eject": "react-scripts eject"
        },
    ....
  3. 根目录创建config-overrides.js

    //配置具体的修改规则
    const { override, fixBabelImports,addLessLoader} = require('customize-cra');
    module.exports = override(
      fixBabelImports('import', {
        libraryName: 'antd',
        libraryDirectory: 'es',
        style: true,
        }),
        addLessLoader({
            lessOptions:{
                javascriptEnabled: true,
                modifyVars: { '@primary-color': 'green' },
            }
        }),
    );

    注意写法不固定,会随着各种插件的更新可能会有所改变,具体还是以个个插件最新写法为主

Last modification:February 28, 2021
如果觉得我的文章对你有用,请随意赞赏