在create-react-app 中启用装饰器语法

方法一: 暴露create-react-app 配置文件

  • 运行命令:
nom run eject
  • 如果报错,说明需要用git 保存当前文件更改后才能使用上面的命令。
    运行如下git命令:
git init 
git add ./
git commit -m 'init'
  • 在 babel 中添加 plugins 配置
    在 package.json 文件中找到 babel 的配置,添加如下代码即可:
"babel": {
    "presets": [
      "react-app"
    ],
+    "plugins": [
+        [
+            "@babel/plugin-proposal-decorators",
+            { "legacy": true }
+        ]
+    ]
}

猜你喜欢

转载自www.cnblogs.com/liea/p/11823723.html