前端npm, yarn, pnpm下载速度太慢,设置国内镜像源的几种方式,体验非一般的感觉

在前端开发的时候使用国外的镜像源速度很慢并且容易下载失败,有时候需要尝试多次才有可能下载成功,很麻烦,因此可以切换为国内镜像源,下面为常用的npm,yarn,pnpm切换国内镜像源(以淘宝为例)的方式。上面那种设置是全局的,以后每次都会自动读取已经设置好的源,如果只是一次性使用,可以使用下面的命令。

一、说明

在前端开发的时候使用国外的镜像源速度很慢并且容易下载失败,有时候需要尝试多次才有可能下载成功,很麻烦,因此可以切换为国内镜像源,下面为常用的npm,yarn,pnpm切换国内镜像源(以淘宝为例)的方式。

二、NPM切换镜像源

1. 查看当前的镜像源。

npm config get registry

2. 设置为淘宝源

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

3. 还原默认源

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

4. 临时使用

上面那种设置是全局的,以后每次都会自动读取已经设置好的源,如果只是一次性使用,可以使用下面的命令

npm --registry https://registry.npm.taobao.org install XXX(模块名)

5、使用cnpm

cnpm是一个命令,用它来代替npm

npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install XXX(模块名)

6.使用nrm

npm install -g nrm
nrm use taobao
nrm ls  # 查看当前可用源命令

三、Yarn 切换镜像源

1. 查看当前镜像源

yarn config get registry

2. 设置为淘宝镜像源

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

3. 切回原镜像源

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

四、pnpm 切换镜像源

1. 查看当前镜像源

pnpm config get registry

2. 设置为淘宝镜像源

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

3. 切回原镜像源

pnpm config set registry https://registry.npmjs.org
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值