配置npm国内源(包含主流npm镜像源地址)

配置npm国内源的方法

通过修改npm的registry配置为国内镜像源,可以显著提升依赖包的下载速度。以下为详细步骤和可选镜像列表:

临时使用单个镜像源

在安装特定包时,可通过--registry参数临时指定镜像源:

npm install [package-name] --registry=https://registry.npmmirror.com

永久修改默认镜像源

执行以下命令永久更换registry:

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

验证配置是否生效:

npm config get registry

国内主流npm镜像源列表

  1. 阿里云镜像

    https://registry.npmmirror.com
    
  2. 腾讯云镜像

    https://mirrors.cloud.tencent.com/npm/
    
  3. 华为云镜像

    https://repo.huaweicloud.com/repository/npm/
    
  4. 清华大学镜像

    https://mirrors.tuna.tsinghua.edu.cn/npm/
    
  5. cnpmjs镜像

    https://r.cnpmjs.org/
    

使用nrm快速切换源

安装nrm源管理工具:

npm install -g nrm

查看可用源列表:

nrm ls

切换镜像源(以阿里云为例):

nrm use taobao

测试各源延迟:

nrm test

恢复默认官方源

如需切换回官方源:

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

注意事项

  • 企业私有源需配置认证信息:

    npm config set always-auth true
    npm config set _auth [base64-encoded-auth-token]
    

  • 镜像源同步可能存在延迟,重要生产依赖建议测试后使用

  • 部分镜像源(如cnpm)可能修改包内容,金融类项目慎用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值