Step1 configure the environment
The following software must be installed!!
-
Homebrew: A free and open source package management system designed to simplify software installation on Mac OS X systems.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" Copy the code
Note: The /usr/localdirectory may be writable during homebrew installation.
sudo chown -R `whoami` /usr/local Copy the code
-
Node is a JavaScript environment based on the Chrome V8 engine
- React Native currently requires NodeJS 5.0 or higher.
brew install node Copy the code
- After installing Node, set up the NPM image to speed up the process (or use the science Web tool). Note: Do not use CNPM! CNPM installed module path is strange, packager can not correctly identify!
npm config set registry https://registry.npm.taobao.org --global npm config set disturl https://npm.taobao.org/dist --global Copy the code
-
Yarn: a package manager that allows you to use code from developers around the world or share your own code. Yarn is a tool that replaces NPM install on Facebook and speeds up node module downloads.
npm install -g yarn react-native-cli Copy the code
- Setting the Mirror Source
yarn config set registry https://registry.npm.taobao.org --global yarn config set disturl https://npm.taobao.org/dist --global Copy the code
-
React Native now requires Xcode 8.0 or later to download
-
Watchman: A tool provided by Facebook to monitor file system changes, Packager can quickly catch changes to files for real-time refresh.
brew install watchman Copy the code
Step2 generate projects
- Initialize a new project
-
Note: The init command creates the latest version by default, whereas current versions 0.45 and above require downloading several third-party libraries such as Boost to compile. In China, it is difficult to download these libraries even if they are over the wall, which makes it impossible to run iOS projects
-
Solution:
A. Install version 0.44.3
React-native Init AwesomeProject -- Version 0.44.3Copy the code
B. Download the third-party library web disk link. After downloading the third-party library web disk link, place it in ~/.rncache
Enter the ~ directory, that is, the user directory cd ~ Create a directory that already exists mkdir .rncache Copy the files in sequence cp ~/Downloads/boost_1_63_0.tar.gz ~/.rncache/ Copy the code
-
- Start Xcode, open it
AwesomeProject/ios
And run
- Note: items will occupy
Port 8081
Make sure the port is not occupied before starting!lsof -i:8081 kill9 the port numberCopy the code
AwesomeProject
- The following can be modified according to your requirements
index.ios.js
- The modified
cmd+s
Save the file for virtual machine usecmd+r
Refresh, that is, visible changes.
conclusion
At this point, a simple ios React-Native project is complete