- 安装
install --save babel-plugin-transform-decorators-legacy
- 扩展webpack的配置
2.1.1 在根目录下创建config-overrides.js文件
const { injectBabelPlugin } = require("react-app-rewired");
module.exports = function override(config, env) {
// 添加装饰器能力
config = injectBabelPlugin(
["@babel/plugin-proposal-decorators", { legacy: true }],
config
);
return config;
};
- 修改package.json 的启动脚本为react-app-rewired启动
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-app-rewired eject"
}