由于npm的默认镜像在国内下载速度较慢,我们可以通过切换到国内镜像源来解决这个问题。
国内镜像源汇总
npm官方原始镜像: https://registry.npmjs.org/
淘宝npm镜像: http://registry.npmmirror.com
阿里云npm镜像: https://npm.aliyun.com
腾讯云npm镜像: https://mirrors.cloud.tencent.com/npm/
华为云npm镜像: https://mirrors.huaweicloud.com/repository/npm/
网易npm镜像: https://mirrors.163.com/npm/
中科大开源镜像站: http://mirrors.ustc.edu.cn/
清华大学开源镜像站: https://mirrors.tuna.tsinghua.edu.cn/
当前使用镜像源
使用命令
npm config get registry
切换镜像源
使用命令
npm config set registry http://mirrors.cloud.tencent.com/npm/
切换为国内的镜像源之后,确认是否切换成功,查看当前使用的npm镜像,命令
npm config get registry
http://mirrors.cloud.tencent.com/npm/
使用nrm工具管理镜像源
使用 nrm 工具可以方便地在多个 npm 源之间切换:
npm install -g nrm
nrm ls # 查看可用源
nrm use taobao # 切换到淘宝镜像