切换npm源的方式
一、使用nrm --NPM registry manager
1、安装nrm
npm install -g nrm
2、查看可选源列表 nrm ls
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/
3、切换源 nrm use
//假如要切换到cnpm
nrm use cnpm
显示结果
Registry has been set to: http://r.cnpmjs.org/
查看切换后的源
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/
4、测速 nrm test
1)测试某个源的相应时间
nrm test taobao
执行结果
* taobao - 188ms
2)测试所有源的相应时间
nrm test
执行结果
npm ---- 16132ms
yarn --- 4662ms
cnpm --- 1639ms
* taobao - 211ms
nj ----- Fetch Error
npmMirror 1920ms
edunpm - 1446ms
二、使用npm config
1、查看源
npm config get registry
执行结果
https://registry.npm.taobao.org/
2、设置源
npm config set registry https://registry.npm.taobao.org/
三、通过CLI命令指定源
在使用命令式进行下载包时,通过--registry 参数指定源
npm --registry https://registry.npm.taobao.org/ install [package-name]
End of the article,share a word with you!
所谓的焦虑和迷茫,其实是身体懒惰和脑子勤奋的矛盾。I'm on my way!
所谓的焦虑和迷茫,其实是身体懒惰和脑子勤奋的矛盾。I'm on my way!