安装React-native 需要的几个重要的步骤:
-
- OS X - This repo only contains the iOS implementation right now, and Xcode only runs on Mac.
- New to Xcode? Download it from the Mac App Store.
- Homebrew is the recommended way to install node, watchman, and flow.
brew install node
. New to node or npm?brew install watchman
. We recommend installing watchman, otherwise you might hit a node file watching bug.brew install flow
. If you want to use flow.
第一、二步就不说了,xCode是IOS开发必备的IDE。
第三步:安装 Homebrew 这个工具是安装node watchman 的前提,首先http://brew.sh/到这个网址 按照提示 安装Homebrew工具。在命令行中输入
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
运行上面命令目前必须通过VPN才能够正确安装,这也是国内局域网的缺陷,20块钱一个月,可以买来玩一个月。不过对于一个程序员来说,VPN这个东西还是非常重要的。根据可以需要购买。
第四、五步按照提示安装即可。到目前为止环境已经搭建完成了。
之后就是验证自己安装的工具是否可用了。在命令行中输入npm start,下面是我运行的时候出现的错误以及解决方案
Watchman took too long to load
Permission settings prevent Watchman from loading. A recent update solves this, get a HEAD install of Watchman if you are experiencing this error.
brew uninstall watchmanbrew install--HEAD watchman
Quick start
-
npm install -g react-native-cli
react-native init AwesomeProject
在使用nom install -g react-native-cli 会出现说
tar.unpack untar error /Users/terrylmay/.npm/react-native-cli/0.1.3/package.tgz 即解压失败。这主要是由于npm文件夹操作是需要root权限的。所以在运行该命令之前加上sudo 即可。
最后,创建AwesomeProject 工程。命令行运行完成之后,你可以看到如下输出:
CXX(target) Release/obj.target/bufferutil/src/bufferutil.o [email protected] node_modules/react-native ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ([email protected]) ├── [email protected] ├── [email protected] ([email protected], [email protected]) ├── [email protected] ├── [email protected] ([email protected]) ├── [email protected] ([email protected]) ├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected]) ├── [email protected] ([email protected], [email protected]) ├── [email protected] ([email protected], [email protected]) ├── [email protected] ([email protected], [email protected], [email protected], [email protected]) ├── [email protected] ([email protected], [email protected], [email protected], [email protected]) ├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]) ├── [email protected] ([email protected]) ├── [email protected] ([email protected], [email protected], [email protected], [email protected]) ├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]) └── [email protected] ([email protected], [email protected], [email protected], [email protected]) Setting up new React Native app in /Users/terrylmay/Project/react-native/react-native_project/AwesomeProject Next steps: Open /Users/terrylmay/Project/react-native/react-native_project/AwesomeProject/AwesomeProject.xcodeproj in Xcode Hit Run button这就表示 创建工程已经成功了。打开工程所在位置,在xCode中打开工程。同时进入命令行 切换到工程所在目录即/*/*/*/*.../*/AwesomeProject 下运行npm start 命令,并且运行xCode中的工程即可看到 react-native工程运行的效果了。如果遇到说在某某目录下找不到 index.ios.js这个文件,说明你打开npm server的目录是不正确的。node server并没有监听到工程所在目录。贴一下运行效果图吧:
如果有疑问的地方可以问我,我们一同探讨。
转载请注明本文地址: react-native安装使用