1.搭建rn环境
必须安装的依赖有:Node、Watchman 和 React Native 命令行工具
我们推荐使用Homebrew来安装 Node 和 Watchman。在命令行中执行下列命令安装:
安装homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
中间可能会报错:
error: could not lock config file /usr/local/Homebrew/.git/config: Permission denied
fatal: could not set ‘core.repositoryformatversion’ to ‘0’
Failed during: git init -q
添加权限即可:
sudo chgrp -R admin /usr/local
sudo chmod -R g+w /usr/local
然后安装node,watchman
brew install node
brew install watchman
如果丧尽天良报了错,只能卸载homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
执行完毕会提示有些配置文件需要手动删除,一定要手动删除哦,不然还会扑街
删除文件
rm 文件名
删除目录
sudo rm -r -f 目录名
删除成功之后,重新安装homebrew
然后安装node watchman
Yarn、React Native 的命令行工具(react-native-cli)
Yarn是 Facebook 提供的替代 npm 的工具,可以加速 node 模块的下载。React Native 的命令行工具用于执行创建、初始化、更新项目、运行打包服务(packager)等任务。
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
3.去你喜欢的workspace新建项目test喽
react-native init test