修改 npm 源

阿里镜像站地址:https://npmmirror.comopen in new window

修改 npm 源

1. 查看当前使用的源地址

npm config get registry

2. 切换为阿里源

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

3. 恢复官方源

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

使用 nrm 管理多个源

nrm(npm Registry Manager)是一个 npm 镜像源管理工具,可以快速切换不同的源。

官方仓库地址:https://github.com/Pana/nrmopen in new window

安装 nrm

npm install -g nrm

查看可用源列表

nrm ls

输出示例:

* 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/

切换源

nrm use taobao

修改 yarn 源

1. 查看当前使用的源地址

yarn config get registry

2. 切换为阿里源

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

3. 恢复官方源

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