React Native 在Mac下的搭建和使用
1.首先安裝Homebrew軟體包管理工具 可以通過他在Mac下安裝 解除安裝軟體
安裝命令是:ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
ruby是電腦自帶的 可以在終端使用命令語句:ruby-v 檢視版本
解除安裝brew的命令是:ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
更新brew的命令是 brew update
2.安裝Node和Watchman
命令列:brew install node
brew install watchman
3.安裝React Native命令後工具
npm install -g yarn react-native-cli
注:我到這一步報了一個錯:Error: Command failed: xcrun instruments -s xcrun: error: unable to find utility "instruments", not a developer tool or in PATH
解決辦法:sudo xcode-select -s /Applications/Xcode.app/Contents/Developer/
4.安裝Xcode 和 AndroidStudio
5.初始化專案: react-native init 專案名
6.執行專案:cd 專案名/
react-native run-ios或者react-native run-android
可以通過command+d 開啟虛擬機器上的開發者選單
建立的專案結構 node_modlues裡面放的是專案依賴的npm包
package.json配置專案的依賴