美文网首页
react-native项目安装mobx时装饰器配置

react-native项目安装mobx时装饰器配置

作者: wangminglang | 来源:发表于2019-04-03 14:03 被阅读0次

    1、rn项目,通过

    npm insatall mobx --save
    npm insatall mobx-react --save
    

    安装mobx后,会报装饰器的错误,通过

    npm install babel-plugin-transform-decorators-legacy --save-dev
    npm install @babel/plugin-proposal-decorators --save-dev
    

    并在package.json中添加:

    "babel": {
        "plugins":[
          ["@babel/plugin-proposal-decorators", {"legacy":true}],
          ["@babel/plugin-proposal-class-properties", {"loose":true}]
        ]
      }
    

    重新运行项目,可以正常运行了。以下为package.json中的代码:

    {
      "name": "name",
      "version": "0.0.1",
      "private": true,
      "scripts": {
        "start": "node node_modules/react-native/local-cli/cli.js start",
        "test": "jest"
      },
      "dependencies": {
        "mobx": "^5.9.4",
        "mobx-react": "^5.4.3",
        "react": "16.8.3",
        "react-native": "0.59.3",
        "react-native-gesture-handler": "^1.1.0",
        "react-navigation": "^3.6.0"
      },
      "devDependencies": {
        "@babel/core": "^7.4.0",
        "@babel/plugin-proposal-decorators": "^7.4.0",
        "@babel/runtime": "^7.4.2",
        "babel-jest": "^24.6.0",
        "babel-plugin-transform-decorators-legacy": "^1.3.5",
        "jest": "^24.6.0",
        "metro-react-native-babel-preset": "^0.53.1",
        "react-test-renderer": "16.8.3"
      },
      "jest": {
        "preset": "react-native"
      },
      "babel": {
        "plugins":[
          ["@babel/plugin-proposal-decorators", {"legacy":true}],
          ["@babel/plugin-proposal-class-properties", {"loose":true}]
        ]
      }
    }
    

    相关文章

      网友评论

          本文标题:react-native项目安装mobx时装饰器配置

          本文链接:https://www.haomeiwen.com/subject/tavabqtx.html