react-native:環境搭建

Any application that than can be written in JavaScript will eventually be written in JavaScript -Jeff Atwood

React Native是Facebook開源的,在Javascript和React的基礎上構建原生的Android和IOS應用的平臺。
React Native着力於提升多平臺的開發效率,Learn once,write anywherehtml

下面簡單介紹下React Native的環境搭建。node

環境要求

最新的OS X系統 ,要開發IOS 應用就必須使用Mac OS系統。
Homebrew:安裝教程 http://brew.sh/ ,Mac上的包管理軟件
Node.js : https://nodejs.org/en/
watchman:https://facebook.github.io/watchman/docs/install.html
facebook的開源的一個文件監視系統。
flow:http://flowtype.org/ facebook開源的一個JavaScript靜態檢查工具react

安裝

安裝Homebrew:android

/usr/bin/ruby -e "$(curl -fsSLhttps://raw.githubusercontent.com/Homebrew/install/master/install)"ios

使用Homebrew安裝node.js:git

brew install nodegithub

安裝watchman:npm

brew install watchmanreact-native

安裝flow :xcode

brew install flow

更新

若是已經安轉了以上的軟件,須要更新到當前最新版本。
首先更新Homebrew的版本庫:

brew update

更新Homebrew庫的內容:

brew upgrade

清除再也不使用的資源:

brew cleanup

安裝react-native

npm是nodejs的包管理,使用npm能夠安裝nodejs的包,react-native也是nodejs的一個包。
使用npm安裝react-native:

npm install -g react-native

安裝react-native命令行工具:

npm install -g react-native-cli

運行命令:

react-native -v

獲得結果:

react-native-cli: 1.0.0
react-native: 0.20.0

react-native安裝成功

第一個react-native項目

新建第一個react-native項目

react-native init HelloRN

o run your app on iOS:
   cd /Users/***/Documents/github/react-native/HelloRN
   react-native run-ios
   - or -
   Open /Users/***/Documents/github/react-native/HelloRN/ios/HelloRN.xcodeproj in Xcode
   Hit the Run button
To run your app on Android:
   Have an Android emulator running (quickest way to get started), or a device connected
   cd /Users/***/Documents/github/react-native/HelloRN
   react-native run-android

運行ios:

react-native run-ios

在當前目錄下面多了一個ios的目錄,裏面新建一個project,HelloRN的項目。

運行Android

react-native run-android

在當前目錄下會多出一個anroid的目錄,裏面是android項目的文件。
運行react-native項目的時候首先會使用react-native start啓動一個端口爲8081的服務,用來提供JavaScript代碼。

相關文章
相關標籤/搜索