1.安裝依賴
必須安裝的依賴有:Node第焰、Watchman 和 React Native 命令行工具以及 Xcode驶睦。
使用Homebrew安裝Node和Watchman恍风。沒有的話需要先安裝Homebrew膏执。
安裝Homebrew
Homebrew, 簡稱brew, Mac系統(tǒng)的包管理器, 用于安裝NodeJS和一些其他必需的工具軟件侧但。
Home-brew 的使用方式:
1)搜索軟件:brew search 軟件名,如brew search wget
2)安裝軟件:brew install 軟件名库北,如brew install wget
3)卸載軟件:brew remove 軟件名爬舰,如brew remove wget
在終端執(zhí)行:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
可通過如下語句查看安裝是否成功以及安裝的Homebrew版本:
brew -v
使用Homebrew來安裝Node.js
React Native需要NodeJS 4.0或更高版本。本文發(fā)布時(shí)Homebrew默認(rèn)安裝的是6.x版本寒瓦,完全滿足要求情屹。
brew install node
使用Homebrew來安裝Watchman
watchman是個(gè)文件監(jiān)控系統(tǒng),他優(yōu)化的是reload文件遍歷機(jī)制杂腰,加入watchman的RN垃你,reload會(huì)加快,沒加的會(huì)遍歷量很高喂很,很慢
watchman介紹
brew install watchman
Yarn惜颇、React Native 的命令行工具(react-native-cli)
Yarn是 Facebook 提供的替代 npm 的工具,可以加速 node 模塊的下載少辣。React Native 的命令行工具用于執(zhí)行創(chuàng)建凌摄、初始化、更新項(xiàng)目毒坛、運(yùn)行打包服務(wù)(packager)等任務(wù)望伦。
npm install -g yarn react-native-cli
安裝完 yarn 后同理也要設(shè)置鏡像源:
yarn config set registry https://registry.npm.taobao.org --global yarn config set disturl https://npm.taobao.org/dist --global
安裝完 yarn 之后就可以用 yarn 代替 npm 了,例如用yarn代替npm install命令煎殷,用yarn add 某第三方庫名代替npm install 某第三方庫名屯伞。
Xcode
React Native 目前需要Xcode 9.4 或更高版本。你可以通過 App Store 或是到Apple 開發(fā)者官網(wǎng)上下載豪直。這一步驟會(huì)同時(shí)安裝 Xcode IDE劣摇、Xcode 的命令行工具和 iOS 模擬器。
Xcode 的命令行工具
啟動(dòng) Xcode弓乙,并在Xcode | Preferences | Locations
菜單中檢查一下是否裝有某個(gè)版本的Command Line Tools
末融。Xcode 的命令行工具中包含一些必須的工具钧惧,比如git
等。