1 不管是配置什么,最好是安装react-app-rewired 这个包来对 cra 创建的项目进行配置调整

 

2 安装好之后 在package.json 里把 scripts 里面的启动项替换成 react-app-rewired

"scripts": {// 这是没有替换的
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
"scripts": {//  替换完成
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test",
    "eject": "react-scripts eject"
  },

3 在于package.json 同级目录下 创建 config-overrides.js

const { override, fixBabelImports, addLessLoader } = require("customize-cra");
const modifyVar = require("./src/lessVars");
//使用了less 预处理 和 antd ui
module.exports = override(
  addLessLoader({
    javascriptEnabled: true,
    modifyVars:modifyVar
  }),
  (module.exports = override(
    fixBabelImports("import", {
      libraryName: "antd",
      libraryDirectory: "es",
      style: true
    })
  ))
);

相关文章:

  • 2021-09-17
  • 2021-11-19
  • 2021-05-28
  • 2021-07-25
  • 2022-12-23
  • 2021-12-24
  • 2021-05-28
猜你喜欢
  • 2021-08-27
  • 2021-08-19
  • 2021-07-29
  • 2021-10-14
  • 2021-05-29
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案