create-react-app 构建的项目使用 mobx

在 create-react-app 命令行构建的 React 项目中使用 Mobx 会出现如下警告:

Support for the experimental syntax ‘decorators-legacy‘ isn‘t currently enabled (9:5):

需要启用 ESNext 的装饰器 (命令行中执行 mac 端)

  1. 先 git add .
  2. git commit -am "Save before ejecting" (然后(注意这里是 am)
  3. npm run eject
  4. 在 package.json 里 babel 添加
 "babel": {
    "presets": [
      "react-app"
    ],
    "plugins": [
      "transform-decorators-legacy"
    ]
  • npm install --save-dev babel-plugin-transform-decorators-legacy (安装该模块中间可能有告警自行消除即可)

按照以上步骤就可以开心的使用 Mobx

文章来自:https://www.cnblogs.com/zhourongcode/p/9875286.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3