- 安装插件
craco
npm i -D @craco/craco
- 创建
craco.config.js
文件放在根目录和package.json
同级
const path = require('path')module.exports = {webpack: {alias: {"@": path.resolve(__dirname, "src")}}
}
- 创建
jsconfig.config.js
文件放在根目录和package.json
同级
{"compilerOptions": {"baseUrl": "./","paths": {"@/*": ["src/*"]}}
}
- 修改
package.json
"scripts": {"start": "craco start","build": "craco build","test": "react-scripts test","eject": "react-scripts eject"},
原本是这样
5. 重启项目使用它