npm install的速度慢,还经常安装失败,换成国内镜像后确实快了好多好多好多好多好多好多好多好多好多好多好多好多好多好多好多好多好多好多好多好多好多好多好多好多好多。

国内镜像:
cnpm镜像地址:http://registry.cnpmjs.org
淘宝镜像地址:https://registry.npm.taobao.org

一. 直接修改镜像地址(设置镜像方法之一):

直接设置镜像有3种方法:

1.npm config set key value 命令,设置指定的镜像地址

1
2
npm config set registry https://registry.npm.taobao.org 
npm info underscore (这个只是为了检验上面的设置命令是否成功,若成功,会返回[指定包]的信息)

2.npm --registry命令

1
npm --registry https://registry.npm.taobao.org info underscore (npm info underscore依然是为了检验是否设置成功)

3.修改配置文件~/.npmrc (win系统在C:\Users\用户名.npmrc) 加入下面内容

1
registry = https://registry.npm.taobao.org

其实1,2,3都是修改npm的配置文件.npmrc .

二. 用封装好的cnpm命令(设置镜像方法之二)

如果觉得直接修改比较麻烦的话,就用cnpm命令吧,先用

1
npm install -g cnpm --registry=https://registry.npm.taobao.org

安装cnpm包,然后就可以敲cnpm install [name]命令了,很方便~~

如果网络状况不好,或者觉得npm install慢的可以换成国内的镜像试下~~~