文档 计算
npm、yarn、pnpm 设置最新国内镜像源(附官方镜像源和最新阿里源),以及 nrm 的使用教程

npm、yarn、pnpm 设置最新国内镜像源(附官方镜像源和最新阿里源),以及 nrm 的使用教程

npm查询源npm get registry 设置源 npm config set registry https://registry.npmmirror.com/ npm config set registry https://registry.npmjs.org/ pnpm p

Related articles

【日本 VPN 推薦】4 個超強的 VPN 翻牆工具輕鬆跨區日本! 苹果上外网加速器-2024六个最佳iOS加速器永久免费官网下载 2024年最好用的VPN推荐(按速度和安全性排行) 如何修复 Windows 10 上的 VPN 错误 809 《2024最新1月》NordVPN Netflix 跨區教學,解鎖觀看各國地區限定電影|香港、台灣、美國影集等任你看

npm

查询源

npm get registry

设置源


npm config set  registry https://registry.npmmirror.com/ 

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

pnpm

pnpm 的镜像源默认

查询源

pnpm get registry

设置源


pnpm config set  registry https://registry.npmmirror.com/ 

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

yarn

查询源

yarn config get registry

设置源


yarn config set  registry https://registry.npmmirror.com/ 

yarn config set registry https://registry.yarnpkg.com/

镜像源集合

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

{
  "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切换镜像源

安装

npm install nrm-g

sudo npm install nrm-g

使用

nrmls – 列出所有的镜像源或查看当前使用的源

nrmls

nrm<add | del> <registry-name> [registry url] – 添加或删除镜像源


 nrmadd testRegistry https://baidu.com/

 nrmdel testRegistry

nrmuse <registry-name> – 使用源

nrmuse taobao

nrmis test test – 测试所有镜像源的速度

nrmtest

总结

清除缓存

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 暂未知 。

nrmuse 时做了什么?

可以看出 nrm 更改的是~/.npmrc 文件

https://npmmirror.com/

推荐文章