npm、yarn、pnpm 设置最新国内镜像源(附官方镜像源和最新阿里源)

npm
查询源
BASH
npm get registry
设置源
BASH
# 国内 淘宝 镜像源
npm config set registry https://registry.npmmirror.com/
# 官方镜像源
npm config set registry https://registry.npmjs.org/
pnpm
pnpm 的镜像源默认

查询源
BASH
pnpm get registry
设置源
BASH
# 国内 淘宝 镜像源
pnpm config set registry https://registry.npmmirror.com/
# 官方镜像源
pnpm config set registry https://registry.npmjs.org/
yarn
查询源
BASH
yarn config get registry
设置源
BASH
# 国内 淘宝 镜像源
yarn config set registry https://registry.npmmirror.com/
# 官方镜像源
yarn config set registry https://registry.yarnpkg.com/
镜像源集合
新增 华为、清华、网易 等镜像地址

请根据当前网络选择最佳镜像。

JSON
{
  "npm": "https://registry.npmjs.org/",
  "yarn": "https://registry.yarnpkg.com/",
  "tencent": "https://mirrors.cloud.tencent.com/npm/",
  "cnpm": "https://r.cnpmjs.org/",
  "taobao": "https://registry.npmmirror.com/",
  "npmMirror": "https://skimdb.npmjs.com/registry/",
  "ali": "https://registry.npm.alibaba-inc.com/",
  "huawei": "https://mirrors.huaweicloud.com/repository/npm/",
  "163": "https://mirrors.163.com/npm/",
  "ustc": "https://mirrors.ustc.edu.cn/",
  "tsinghua": "https://mirrors.tuna.tsinghua.edu.cn/"
}
使用 nrm 切换镜像源
安装
BASH
npm install nrm -g
# or
sudo npm install nrm -g
使用
nrm ls - 列出所有的镜像源或查看当前使用的源
BASH
nrm ls


nrm <add | del> <registry-name> [registry url] - 添加或删除镜像源
BASH
# 添加源
nrm add testRegistry https://baidu.com/
# 删除源
nrm del testRegistry


nrm use <registry-name> - 使用源
BASH
nrm use taobao
nrm test - 测试所有镜像源的速度
BASH
nrm test


总结
清除缓存
BASH
npm cache clean --force
设置后 yarn 不生效?
yarn 版本 1.22.22
yarn 并未读取当前 项目目录 或用户(~/.npmrc)目录下的 .npmrc 文件的 registry 字段,在查询 yarn v1 官网和相关 issue(https://github.com/yarnpkg/yarn/issues/2118)未发现相关描述
yarn v1.x 版本中仍会读取 .npmrc 的相关字段,但会优先使用 .yarnrc 中的值,由于 yarn config 中的 registry 字段无法删除(delete 后仍有默认值),在项目外只能使用命令更改,或修改 .yarnrc。至于未读取当前项目下的 .npmrc 中的 registry 暂未知。

nrm use 时做了什么?
可以看出 nrm 更改的是 ~/.npmrc 文件

https://npmmirror.com/

推荐文章


作者: kshao
链接: https://ksh7.com/posts/npm-registry/index.html#%E6%B8%85%E9%99%A4%E7%BC%93%E5%AD%98
来源: kshao-blog-前端知识记录
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yunfanleo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值