通过安装customize-cra插件来实现
在根目录新建config-overrides.js
const {
override,
addWebpackAlias
} = require('customize-cra')
const path = require('path')
module.exports = override(
addWebpackAlias({
'@': path.resolve(__dirname, 'src'),
'@components': path.resolve(__dirname, 'src/components'),
'@views': path.resolve(__dirname, 'src/views'),
})
)
修改package.json文件
原本之前的
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
},
修改之后
scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
},
这边保存重启一下即可