国内npm源镜像(npm加速下载) 指定npm镜像

国内的 NPM 源镜像可以通过指定不同的镜像地址来加速下载依赖包。以下是几种常用的国内 NPM 源镜像地址和设置方法:

常用国内 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 镜像:

可以通过以下命令全局设置 NPM 镜像:

npm config set registry <镜像地址>

 例如,设置淘宝 NPM 镜像:

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

要验证是否设置成功,可以运行以下命令查看当前配置的 registry:

npm config get registry

临时使用镜像:

你也可以在安装包时临时指定镜像源,而不修改全局设置:

npm install <package-name> --registry=https://registry.npmmirror.com

例如安装 lodash:

npm install lodash --registry=https://registry.npmmirror.com

使用 cnpm 作为替代方案

cnpm 是淘宝团队开发的 NPM 客户端,专门用来替代 NPM 并使用淘宝镜像源。安装 cnpm 后,所有的包都会通过淘宝源进行下载,步骤如下:

安装 cnpm:

npm install -g cnpm --registry=https://registry.npmmirror.com

安装包时使用 cnpm:

cnpm install lodash

使用 nrm 管理镜像源

nrm 是一个 NPM 源管理工具,帮助用户更方便地切换不同的 NPM 镜像源。步骤如下:

安装 nrm:

npm install -g nrm

查看可用的镜像源:

nrm ls

切换到淘宝镜像:

nrm use taobao

清理 NPM 缓存

在切换镜像源后,如果遇到缓存问题或安装速度不理想,可以清理 NPM 缓存:

npm cache clean --force

更新npm到最新版本

要将 npm 更新到最新版本,可以使用以下命令:

npm install -g npm

 验证 npm 版本:

更新完成后,可以运行以下命令来检查 npm 是否成功更新到最新版本:

npm -v

这会显示当前安装的 npm 版本号。 

切换回官方源

要切换回 NPM 的官方源,可以使用以下命令:

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

验证切换是否成功:

可以运行以下命令查看当前配置的注册表源:

npm config get registry

这应该会返回 https://registry.npmjs.org/,确认你已经成功切换回官方源。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

无限循环者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值