为什么需要切换npm 镜像源?
因为 npm 存储包文件的服务器在国外,从服务器拉取资源的时候速度会比较慢,为了解决这个问题。相关开发团队把 npm 在国内做了一个备份
npm 镜像源相关操作
1、查看当前源
npm config ls
# 或者
npm config get registry
2、设置镜像源
npm config ls
# 或者
npm config set registry https://registry.npmmirror.com/
3、相关镜像源地址
- 官方:https://www.csdn.net/
- 淘宝: https://registry.npmmirror.com/
(npm.taobao.org 和 http://registry.npm.taobao.org 将在 2022.06.30 号正式下线和停止 DNS 解析。npm.taobao.org => http://npmmirror.com;registry.npm.taobao.org => http://registry.npmmirror.com) - 阿里云: https://npm.aliyun.com/
- 腾讯云: https://mirrors.cloud.tencent.com/npm/
- 华为云: https://mirrors.huaweicloud.com/repository/npm/
- 网易: https://mirrors.163.com/npm/
npm 镜像管理工具 nrm
为了方便快捷的切换 npm 的镜像,可以使用 nrm
管理工具来管理
1、下载 nrm
全局安装 nrm 镜像管理工具
npm install nrm -g
2、查看是否安装成功
nrm -V
3、查看所有源
nrm ls
4、查当前源
nrm current
5、切换源
nrm use <registry>
# nrm use taobao
6、添加源
nrm add <registry> <url>
# nrm add xxx https://example.com/
7、删除源
nrm del <registry>
# nrm del xxx
8、测试源响应时间
nrm test <registry>
# nrm test xxx