create-react-app对webpack的配置进行了封装并默认隐藏了配置文件,如何不通过 yarn eject 的方式暴露配置文件而进行webpack的自定义配置呢?
使用craco和craco-antd进行再配置
不会直接去修改create-react-app的默认配置,而是在create-react-app配置的基础上进行扩展。类似的解决方案还有react-app-rewired
使用步骤
1.安装 craco
$ yarn add @craco/craco
# OR
$ npm install @craco/craco --save
2.在项目根目录新建craco.config.js
文件
my-app
├── node_modules
├── craco.config.js
└── package.json
3.修改 package.json
里的启动配置
/* package.json */
"scripts": {
- "start": "react-scripts start",
+ "start": "craco start",
- "build": "react-scripts build",
+ "build": "craco build",
- "test": "react-scripts test",
+ "test": "craco test",
}