$ 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”,
}
4.在生产模式下取消控制台的console配置
取消console,最常用方法是安装uglifyjs-webpack-plugin
const UglifyJsPlugin = require(‘uglifyjs-webpack-plugin’);
const UglifyJsPlugin = require(‘uglifyjs-webpack-plugin’);
module.exports = {
webpack: {
// 别名
alias: {
“@”: path.resolve(“src”),
},
plugins: [
new UglifyJsPlug