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

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时装饰器配置)