yarn ,cnpm ,pnpm ,npm 设置镜像源

1. npm

设置镜像源
# 设置淘宝镜像
npm config set registry https://registry.npmmirror.com

# 或设置腾讯云镜像
npm config set registry https://mirrors.cloud.tencent.com/npm/
恢复官方源
npm config set registry https://registry.npmjs.org/

2. yarn (Classic 版本)

设置镜像源
# 设置淘宝镜像
yarn config set registry https://registry.npmmirror.com

# 或设置腾讯云镜像
yarn config set registry https://mirrors.cloud.tencent.com/npm/
恢复官方源
yarn config set registry https://registry.yarnpkg.com

3. yarn (Berry 版本)

Yarn Berry(2.x+)使用 .yarnrc.yml 文件配置:

npmRegistryServer: "https://registry.npmmirror.com"

4. pnpm

设置镜像源
# 设置淘宝镜像
pnpm config set registry https://registry.npmmirror.com

# 或设置腾讯云镜像
pnpm config set registry https://mirrors.cloud.tencent.com/npm/
恢复官方源
pnpm config set registry https://registry.npmjs.org/

5. cnpm

cnpm 是淘宝定制的 npm 客户端,默认已配置淘宝源。如需自定义:

# 设置镜像源(不推荐,建议直接使用 npm/yarn/pnpm + 镜像)
cnpm config set registry https://registry.npmmirror.com

常用镜像地址

镜像名称Registry URL备注
淘宝镜像https://registry.npmmirror.com国内首选,更新频率高
腾讯云镜像https://mirrors.cloud.tencent.com/npm/腾讯云服务,稳定性强
华为云镜像https://repo.huaweicloud.com/repository/npm/华为云提供
官方源https://registry.npmjs.org/国际用户使用
私有仓库http://your-private-registry.local企业内网私有仓库地址

额外配置(可选)​

设置二进制镜像(适用于 Node.js C++ 模块)​
# npm
npm config set disturl https://npmmirror.com/mirrors/node

# yarn
yarn config set disturl https://npmmirror.com/mirrors/node

# pnpm
pnpm config set disturl https://npmmirror.com/mirrors/node
设置 Electron 镜像(加速 Electron 下载)​
# npm
npm config set electron_mirror https://npmmirror.com/mirrors/electron/

# yarn
yarn config set electron_mirror https://npmmirror.com/mirrors/electron/

验证配置

查看当前镜像源:

# npm
npm config get registry

# yarn (Classic)
yarn config get registry

# pnpm
pnpm config get registry

注意事项

  1. 权限问题:全局配置需要管理员权限(Windows 用户以管理员身份运行终端)。
  2. 项目级配置:可在项目根目录添加 .npmrc 或 .yarnrc 文件覆盖全局配置。
  3. 协议安全:企业私有仓库可能需要 http 协议,建议使用 HTTPS 避免安全问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值