我是靠谱客的博主 斯文宝贝,最近开发中收集的这篇文章主要介绍npm、yarn如何设置源,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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

  • npm: https://www.npmjs.com/package/cgr
  • github: https://github.com/daysai/cgr

安装:

npm install -g cgr

默认源列表:

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共用的源

切换源:

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为空,表示同时切换源

添加私有源:

cgr add iverson http://registry.private.com
add registry iverson 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/
  iverson --- http://registry.private.com/

删除私有源:

cgr del iverson
delete registry iverson success

源响应时间测试:

cgr test

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

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

最后

以上就是斯文宝贝为你收集整理的npm、yarn如何设置源的全部内容,希望文章能够帮你解决npm、yarn如何设置源所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(54)

评论列表共有 0 条评论

立即
投稿
返回
顶部