學習RN開發的過程中,有許多需要命令操作的功能,對涉及到的命令進行總結。
- 搭建環境階段
首先需要使用命令行下載安裝 Chocolatey、python 2 、node.js、Yarn。詳情:React Native 中文網—文檔—搭建開發環境
功能 | 命令 |
---|---|
安裝Chocolatey | @powershell -NoProfile -ExecutionPolicy Bypass -Command “iex ((new-object net.webclient).DownloadString(‘https://chocolatey.org/install.ps1‘))” && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin |
安裝 python 2 | choco install python2 |
安裝 node | choco install nodejs.install |
設置node鏡像 | npm config set registry https://registry.npm.taobao.org –global npm config set disturl https://npm.taobao.org/dist –global |
安裝Yarn | 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 |
2. 項目開發
功能 | 命令 |
---|---|
創建項目 | react-native init [工程名] –version [版本號] |
啓動服務 | npm start 或 react-native start |
運行android | react-native run-android |
運行ios | react-native run-ios |
運行release版本 | react-native run-android –variant=release |
Android 5.0以上wifi鏈接本地開發服務器 | adb reverse tcp:8081 tcp:8081 |
3. 下載別人開源項目的導入
功能 | 命令 |
---|---|
安裝react-native | npm install |
link native功能 | react-native link |
運行android | react-native run-android |
4. 引入第三方庫
功能 | 命令 |
---|---|
使用Yarn引入 | yarn add 某第三方庫名 |
使用npm引入 | npm install –save 某第三方庫名 |
向native模塊中添加了各種依賴和導包的操作 | react-native link |
第三方庫鏈接到項目 | rnpm link |
安裝rnpm | npm install rnpm -g |
5. 刪除第三方庫
功能 | 命令 |
---|---|
只是刪除組件 | npm uninstall 某第三方庫名 |
刪除在RN的package.json中的依賴 | npm uninstall -s -D -O 某第三方庫名 |
第三方庫鏈接到項目 | rnpm link |
安裝rnpm | npm install rnpm -g |
6. 其他命令
功能 | 命令 |
---|---|
查看當前reactNative版本 | react-native –version |
更新一下項目依賴 | react-native upgrade |
查看服務器端的reactNative的各版本信息 | npm info react-native |
項目降級或升級到指定版本 | npm install –save [email protected] |
查看 Node 已經實現的 ES6 特性 | node –v8-options |