React Native 使用mobx

2019-03-19  本文已影响0人  树袋Papa

1. React Native 0.56.0 以前的版本

1.1. 安装依赖mobx和mobx-react

npm i mobx mobx-react --save

1.2. 安装babel插件,以使用ES7 decorators

npm i babel-plugin-transform-decorators-legacy --save-dev

1.3. 更新.babelrc

{   "presets": ["react-native"],   "plugins": ["transform-decorators-legacy"] }

2. React Native 版本 0.56.0及以上

安装 @babel/plugin-proposal-decorators 代替 babel-plugin-transform-decorators-legacy

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

2.1 配置 .babelrc

"presets": ["react-native"], 

"plugins": [

    [

      "@babel/plugin-proposal-decorators",

      {        "legacy": true      }

    ]

  ]

}

3. React Native 0.60及以上

安装metro-react-native-babel-preset

npm i metro-react-native-babel-preset --save-dev

配置babel.config.js

module.exports = {

    presets: ['module:metro-react-native-babel-preset'],

    "plugins": [

        [

            "@babel/plugin-proposal-decorators",

            {

                "legacy": true

            }

        ]

    ]

};


Reference

React Native with MobX — Getting Started


@date 2019-03-18

@author liushuohui

上一篇下一篇

猜你喜欢

热点阅读