零、前言
额 (╯﹏╰) ,怎么是从零开始的,这很程序猿…。
npm作为node依赖包管理的主流工具之一,那么在日常的开发使用中,你是否会经常性遇到一些问题呢?
比如:安装依赖慢或者失败的情况出现?如果有你又是怎么解决的呢?
这个大多数是由于镜像源服务器在国外导致,当然作用主流的依赖包管理工具之一,怎么会没有其它的镜像服务器呢?
这里推荐 淘宝镜像 或其它方案作为替换目标。
一、cnpm
是淘宝团队做的一套镜像,安装完成后的镜像地址是淘宝镜像
1 2
| npm install -g cnpm cnpm -v // 查看安装的信息
|
二、直接更改npm镜像
1 2 3 4 5
| // 单次使用 npm install --registry=https://registry.npm.taobao.org
// 永久性更改 npm config set registry https://registry.npm.taobao.org
|
说一个大多数人都会遇到头痛的问题?
什么?
node-sass又双叒叕安装失败啦!!!
那么你可以单独拿出来安装,只指定大版本,便可解决这个问题。
1 2
| // npm install -D node-sass@4.x
|
三、nrm工具
1、查看所有源(yarn对应到yrm)
1 2 3 4 5 6 7 8 9 10
| // 查看所有源 nrm ls npm -------- https://registry.npmjs.org/ yarn ------- https://registry.yarnpkg.com/ cnpm ------- http://r.cnpmjs.org/ * taobao ----- https://registry.npm.taobao.org/ nj --------- https://registry.nodejitsu.com/ npmMirror -- https://skimdb.npmjs.com/registry/ edunpm ----- http://registry.enpmjs.org/
|
2、设置源
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| // 设置源 nrm add xxx(名称) xxxx(地址) // 如: 设置公司的私有镜像源,nrm add dtstack http://registry.npm.dtstack.com/ // * 表示当前使用源 npm -------- https://registry.npmjs.org/ yarn ------- https://registry.yarnpkg.com/ cnpm ------- http://r.cnpmjs.org/ * taobao ----- https://registry.npm.taobao.org/ nj --------- https://registry.nodejitsu.com/ npmMirror -- https://skimdb.npmjs.com/registry/ edunpm ----- http://registry.enpmjs.org/ xxx ---- http://xxxx/ // 删除源 nrm del xxx
|
3、使用源
1 2 3 4 5
| // 使用哪个源,如淘宝源 nrm use taobao
// 测试源速度 nrm test taobao
|
参考资料:
nrm