环境安装
1、安装Xcode最新版 (里面包含了常用的开发环境,如git)
2、安装 Iterm2、Oh My Zsh (可选安装)
参考自: 菜鸟级 Mac 配置(二)
3、安装 Homebrew (Mac os x上的包管理,如Ubuntu的 apt-get)
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
4、安装 nvm (nodejs 的版本管理)
git clone https://github.com/cnpm/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`
. ~/.nvm/nvm.sh
然后打开 ~/.bashrc 、 ~/.profile , or ~/.zshrc这三个文件,在其中添加:
注: 上面的文件可能会没有,请自行创建, 如果安装了 oh my zsh , 会自动生成 .zshrc 文件
source ~/.nvm/nvm.sh
5、安装nodejs
nvm install node && nvm alias default node
6、替换 npm 仓库为淘宝国内源
npm config set registry https://registry.npm.taobao.org --global
npm config set disturl https://npm.taobao.org/dist --global
7、安装 watchman
(实时监测文件修改), flow
(JavaScript 的静态类型检查器)
brew install watchman
brew install flow
8、安装 react-native-cli
cnpm install -g react-native-cli
9、安装 rnpm (React Native Package Manager)
npm install -g rnpm
10、创建项目
react-native init hello
加上 --verbose
显示安装详细信息
另,执行init时切记不要在前面加上sudo(否则新项目的目录所有者会变为root而不是当前用户,导致一系列权限问题,请使用chown修复)。
目录结构如下:
.
├── android
├── index.android.js
├── index.ios.js
├── ios
├── node_modules
├── npm-debug.log
└── package.json
2695 directories, 14329 files
11、设置依赖并运行
npm install
rnpm link
react-native run-ios
npm start