1.安装模块
使用cnpmcnpm i @babel/plugin-proposal-decorators customize-cra react-app-rewired -D
或者使用yarnyarn add @babel/plugin-proposal-decorators customize-cra react-app-rewired -D
2.根目录下创建config-overrides.js文件
文件内写入以下代码
// 参考配置连接:https://www.npmjs.com/package/customize-cra
const {override,addDecoratorsLegacy}=require("customize-cra");
module.exports=override(
addDecoratorsLegacy(),//配置装饰器模式
);
3.修改package.json运行命令
"scripts": {
"start": "react-app-rewired start", // update
"build": "react-app-rewired build", // update
"test": "react-app-rewired test", // update
"eject": "react-scripts eject"
},