1、安装环境
Mac平台需要的环境
Node, Watchman, React Native command line interface, Xcode.
1)安装Node & Watchman
brew install node
brew install watchman
2)安装yarn命令(可选)
npm install-g yarn--registry=https://registry.npm.taobao.org
配置源
yarn config set registry https://registry.npm.taobao.org-gyarn config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass-g
2、创建新的本地项目
npx react-native init xxx
或者可以在此命令后面增加“—version”参数(注意是两个杠)创建指定react版本的项目。例如npx react-native init MyApp --version 0.44.3。注意版本号必须精确到两个小数点
3、运行项目
1)通过npx命令运行
cd AwesomeProject
npx react-native start
npx react-native run-ios
2)通过yarn命令运行(可选)
cd AwesomeProject
yarn ios
网友评论