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源的工具


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM