一、国内npm镜像源
- 淘宝NPM镜像
registry.npmmirror.com/ - 阿里云NPM镜像
npm.aliyun.com/ - 腾讯云NPM镜像
mirrors.cloud.tencent.com/npm/ - 华为云NPM镜像
repo.huaweicloud.com/repository/… (需要自己开通) - 网易NPM镜像
mirrors.163.com/npm/ - 中国科学技术大学开源NPM镜像
mirrors.ustc.edu.cn/npm/ - 清华大学开源NPM镜像
mirrors.tuna.tsinghua.edu.cn/npm/ (需要镜像申请) - CNPM镜像
r.cnpmjs.org/
二、nrm介绍
nrm是一个npm仓库源切换工具,用于不同镜像仓库的地址切换管理。
nrm仓库:github.com/Pana/nrm
全局安装
# npm
npm install nrm -g
# yarn
yarn global add nrm
# pnpm
pnpm add nrm -g
查看镜像仓库列表
$ nrm ls
* npm ---------- https://registry.npmjs.org/
yarn --------- https://registry.yarnpkg.com/
tencent ------ https://mirrors.tencent.com/npm/
cnpm --------- https://r.cnpmjs.org/
taobao ------- https://registry.npmmirror.com/
npmMirror ---- https://skimdb.npmjs.com/registry/
huawei ------- https://repo.huaweicloud.com/repository/npm/
使用某个镜像仓库
nrm use <registry>
增加新的仓库
nrm add <registry> <url>
比如:将上述清华大学的镜像加入到列表可以执行 nrm add tsinghua https://mirrors.tuna.tsinghua.edu.cn/npm/ 即可。
删除镜像仓库
nrm del <registry>
其他的命令可看 github.com/Pana/nrm?ta…
三、npm镜像源配置
设置全局源
通过上述 nrm use 命令或直接更改本地npm仓库地址 npm config set registry <url>
设置项目源
在项目根目录下创建 .npmrc 文件,通过配置仓库地址,可将某些依赖指向自己的私有仓库。
registry=https://registry.npmmirror.com
设置空间源
@my-group:registry=https://registry.npmmirror.com
这个配置可对某个命名空间下的所有包生效。例如:@vitejs/xxx。