Node与Npm国内最新镜像配置(淘宝镜像/清华大学镜像)

1.淘宝镜像:

node_mirror: https://npmmirror.com/mirrors/node/
npm_mirror: https://npmmirror.com/mirrors/npm/

2.清华大学镜像:

node_mirror: https://mirrors.tuna.tsinghua.edu.cn/nodejs-release/
npm_mirror: https://mirrors.tuna.tsinghua.edu.cn/nodejs-release/npm/

查看电脑当前镜像源:

npm get registry

临时更换镜像:

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

永久更换镜像

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

3.更换 nrm(Node Registry Manager)管理镜像源

nrm 是一个 npm 镜像源管理器,可以让你轻松地在不同的 npm 镜像源之间切换。

安装 nrm

npm install -g nrm

查看可用的镜像源

nrm ls

使用 nrm 切换到某个镜像源

nrm use npmmirror  # 使用 npmmirror 镜像源
# 或者使用 nrm use taobao 来使用淘宝的官方镜像源

4.更换 cnpm(一个由淘宝团队开发的 npm 客户端)

cnpm 是淘宝团队为解决国内网络问题而开发的 npm 客户端,它内置了淘宝的 npm 镜像。

安装 cnpm

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

使用 cnpm 安装包

cnpm install express

5.使用 yarn 来管理依赖(可选)

Yarn 是另一个流行的 JavaScript 包管理工具,它也可以配置使用国内的镜像源。

安装 yarn

npm install -g yarn

配置 yarn 使用淘宝镜像

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

注意:

确保在执行任何更改之前,备份当前的配置,以便在需要时可以轻松恢复。可以通过运行 npm config list -l 查看所有配置项及其值。如果要恢复默认设置,可以使用如下命令:

npm config delete registry # 删除 registry 设置,恢复为默认值(通常是官方源)

在使用 Maven 构建项目时,如果需要下载 Node.js 相关的依赖包,通常会通过插件如 `frontend-maven-plugin` 来实现。由于默认的 Node.js 官方源位于国外,国内访问速度较慢,因此可以配置镜像源以提高下载速度。 ### 镜像配置方式 Maven 本身不直接下载 Node.js,而是通过插件调用系统网络或内置机制下载。因此,配置 Node.js 下载镜像源的方式通常是在插件中指定自定义的 URL,而不是通过 Maven 的 `<mirrors>` 配置。 例如,在 `pom.xml` 文件中使用 `frontend-maven-plugin` 插件时,可以指定 Node.js 的下载地址为国内镜像: ```xml <plugin> <groupId>com.github.eirslett</groupId> <artifactId>frontend-maven-plugin</artifactId> <version>1.12.0</version> <executions> <execution> <id>install node and npm</id> <goals> <goal>install-node-and-npm</goal> </goals> <configuration> <nodeVersion>v16.14.2</nodeVersion> <npmVersion>8.5.0</npmVersion> <nodeDownloadRoot>https://npmmirror.com/mirrors/node/</nodeDownloadRoot> </configuration> </execution> </executions> </plugin> ``` 上述配置中,`nodeDownloadRoot` 被设置为 `https://npmmirror.com/mirrors/node/`,这是由淘宝 NPM 镜像维护的 Node.js 镜像源,能够显著提升国内用户的下载速度[^2]。 ### 可用的 Node.js 镜像源地址 除了淘宝镜像,还可以使用其他镜像源来下载 Node.js,例如: - **华为云镜像**:`https://mirrors.huaweicloud.com/nodejs/` - **清华大学镜像**:`https://mirrors.tuna.tsinghua.edu.cn/nodejs-release/` - **阿里云镜像**:`https://npm.taobao.org/mirrors/node/`(淘宝镜像一致) 这些镜像源均可在 `frontend-maven-plugin` 的配置中作为 `nodeDownloadRoot` 的值使用,以替代默认的 `https://nodejs.org/dist/`[^3]。 ### 示例:使用华为云镜像下载 Node.js ```xml <plugin> <groupId>com.github.eirslett</groupId> <artifactId>frontend-maven-plugin</artifactId> <version>1.12.0</version> <executions> <execution> <id>install node and npm</id> <goals> <goal>install-node-and-npm</goal> </goals> <configuration> <nodeVersion>v18.16.0</nodeVersion> <nodeDownloadRoot>https://mirrors.huaweicloud.com/nodejs/</nodeDownloadRoot> </configuration> </execution> </executions> </plugin> ``` 通过上述配置,Maven 插件将从华为云镜像下载 Node.js,从而避免因网络问题导致的构建失败或缓慢。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

by__csdn

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

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

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

打赏作者

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

抵扣说明:

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

余额充值