1.安装依赖
yarn add react-app-rewired customize-cra babel-plugin-import less less-loader
react-app-rewired:重写脚手架配置
customize-cra:修改webpack配置
babel-plugin-import:将 import 的写法自动转换为按需引入的方式
less:使用less
less-loader:将less文件转化为css
create-creact-app项目,如果需要手动修改配置,需先npm run eject弹出配置,这个过程是不可逆的
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