React Native 初始化项目慢的解决办法
初始化React Native:react-native init ProjectName
由于墙的原因,即便开ss也会经常卡着不动。再次感谢方教授!
先看下NMP官网对 node-gyp 的介绍
node-gyp
Node.js native addon build tool
node-gyp
is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js. It >bundles thegyp
project used by the Chromium team and takes away the pain of dealing with the various differences in build platforms. It is the replacement to thenode-waf
program which is removed for node v0.8. If you have a native addon for node that still has a wscript file, then you should definitely add a binding.gyp file to support the latest versions of node.
在初始化的过程中,npm
会下载源码然后使用 node-gyp
进行编译,而 node-gyp 编译时候需要 NodeJs 源码来提供头文件,所以它会先尝试下载 NodeJs 源码,而在天朝墙外 CDN 经常抽风,下载 NodeJs 源码奇慢无比,那么自然要卡很久。
解决方法:先把 NodeJs 源码下载到本地,然后提取给 node-gyp。
terminal下( nodejs 及 wget 自行安装 ):
touch node-gyp.sh
vi node-gyp.sh
1 | # nodejs 版本号 |
保存退出后执行 bash node-gyp.sh
最后再替换 npm 淘宝镜像
:
npm config set registry=http://registry.npm.taobao.org/
这样 React Native初始化会快很多。
React Native 初始化项目慢的解决办法