如何更换yarn或者npm镜像源
发布日期:2021-05-04 18:16:24 浏览次数:27 分类:原创文章

本文共 1123 字,大约阅读时间需要 3 分钟。

yarn 或者 npm 的默认镜像源比较慢。可以如下更新

npm config get registry  // 查看源npm config set registry https://registry.npm.taobao.org/  // 设置源yarn config get registry  // 查看源yarnyarn config set registry https://registry.npm.taobao.org/  // 设置源yarn

以上的设置是全局的。即设置之后就全局有效了。重启命令行仍旧是生效的,其实是改变了你家目录的.npmrc和.yarn文件。

PS C:\Users\86186> cat .npmrcregistry=https://registry.npm.taobao.org/PS C:\Users\86186> cat .yarnrc# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.# yarn lockfile v1registry "https://registry.npm.taobao.org/"lastUpdateCheck 1607068611475

以上,所以是永久生效的。如果是想临时生效。可以使用以下命令:

npm install --registry=https://registry.npm.taobao.org# 比如有些时候只是想使用一次,如下npm install -g cnpm --registry=https://registry.npm.taobao.org

最后npm有个非常方便源管理软件nrm。可以让你快速的切源。

npm install -g nrmPS C:\Users\86186> 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/

之后输入nrm use npm 这样即可切换回npm的官方源。

上一篇:手把手教你用docker部署自己的npm私服verdaccio
下一篇:vue中更好的按需引入echarts

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2025年03月26日 18时12分33秒