240
世界上有10种人,一种懂二进制,另一种不懂二进制。

npm/yarn查看当前使用源与设置其它源

1.前言
npm,yarn查看源和换国内源,毕竟国外的资源下载,在国内速度是非常慢的。cgr(change registry | yarn & npm registry manager)是一款能同时、分开管理npm、yarn源的工具工具更好管理 
2.内容
2.1
npm, yarn查看源和换源:
npm config get registry  // 查看npm当前镜像源

npm config set registry https://registry.npmjs.org

yarn config get registry  // 查看yarn当前镜像源

yarn config set registry https://registry.yarnpkg.com 
镜像源地址部分如下:
npm --- https://registry.npmjs.org/

npm --- https://registry.npm.taobao.org/

yarn --- https://registry.yarnpkg.com/

yarn --- https://registry.npm.taobao.org/

cnpm --- https://r.cnpmjs.org/

taobao --- https://registry.npm.taobao.org/

nj --- https://registry.nodejitsu.com/

rednpm --- https://registry.mirror.cqupt.edu.cn/

npmMirror --- https://skimdb.npmjs.com/registry/

deunpm --- http://registry.enpmjs.org/

2.2
cgr一款能同时、分开管理npm、yarn源的工具

2.2.1 安装
npm install -g cgr
2.2.2 默认源列表
cgr ls

N npm ---- https://registry.npmjs.org/
  cnpm --- http://r.cnpmjs.org/
Y taobao - https://registry.npm.taobao.org/
  yarn --- https://registry.yarnpkg.com/

N代表npm,Y代表yarn,*代表npm和yarn共用的源
2.2.3源切换
cgr use cnpm
npm registry has been set to: http://r.cnpmjs.org/
yarn registry has been set to: http://r.cnpmjs.org/

cgr use cnpm y
yarn registry has been set to: http://r.cnpmjs.org/

cgr use cnpm n
npm registry has been set to: http://r.cnpmjs.org/

y/yarn代表yarn切换,n/npm代表npm切换,大小写均可;type为空,表示同时切换源
2.2.4添加私有源
cgr add test http://registry.private.com
add registry test success

cgr ls
N npm ---- https://registry.npmjs.org/
  cnpm --- http://r.cnpmjs.org/
Y taobao - https://registry.npm.taobao.org/
  yarn --- https://registry.yarnpkg.com/
  test --- http://registry.private.com/
2.2.5删除私有源 
cgr del test
delete registry test success
2.2.6源响应时间测试
cgr test

N npm ---- 693ms
  cnpm --- 223ms
Y taobao - 102ms
  yarn --- 929ms

说明:cgr 是基于nrm的改进版本,进行了一些优化,能同时管理npm、yarn源。底层通过bash命令进行源切换操作,避免了直接操作.yarnrc等源管理文件。

3.参考
1. yarn/npm 源地址查看与修改
2
.介绍一款能同时、分开管理npm、yarn源的工具

posted @ 2020-09-15 10:10  unionline  阅读(4321)  评论(1编辑  收藏  举报