react-native mac搭建环境
2019-04-16 本文已影响0人
Crassus
安装依赖
必须安装的依赖有:Node、Watchman、yarn 和 React Native 命令行工具以及 Xcode。
brew install node // node版本必须在v8.3以上版本, 我的版本是v10.15.3
brew install watchman
// 设置 npm 镜像以加速后面的过程
npm config set registry https://registry.npm.taobao.org --global
npm config set disturl https://npm.taobao.org/dist --global
npm install -g yarn react-native-cli
// 安装完 yarn 后同理也要设置镜像源:
yarn config set registry https://registry.npm.taobao.org --global
yarn config set disturl https://npm.taobao.org/dist --global
安装第三方库
react-native 0.45版本以上必须依赖第三方库才可以正常运行。
1.查看必须安装第三方文件

2.下载这些文件,不需要解压

3.将下载的文件都放在~/.rncache
即可,如果没有自己创建。

创建新项目
react-native init AwesomeProject
// 创建指定react-native版本的项目
react-native init AwesomeProject --version 0.44.3
编译并运行
cd AwesomeProject
react-native run-ios
// 跑安卓
react-native run-android
修改项目App.js文件,测试功能

[图片上传中...(image.png-65ab37-1555386190066-0)]
调试
模拟器情况:电脑cmd+r刷新页面;cmd+d弹出操作菜单
真机情况:左右晃动弹出操作菜单
