前端npm, yarn, pnpm下载速度太慢,设置国内镜像源的几种方式,让其速度飞起来

一、说明

刚安装的npm使用默认的源会感觉特别特别慢,所以,非常有必要使用国内的源,比如说众所周知的淘宝镜像源

二、NPM设置

  1. 查看当前源
npm config get registry
  1. 设置为淘宝源
npm config set registry https://registry.npm.taobao.org
# 还原默认源:npm config set registry https://registry.npmjs.org/

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

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

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

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

5.使用nrm

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

三、Yarn 设置国内镜像

  1. 查看当前镜像
yarn config get registry
  1. 设置为淘宝镜像
yarn config set registry https://registry.npmmirror.com
  1. 切回原镜像
yarn config set registry https://registry.yarnpkg.com

三、pnpm 设置国内镜像

  1. 查看当前镜像
pnpm config get registry
  1. 设置为淘宝镜像
pnpm config set registry https://registry.npmmirror.com
  1. 切回原镜像
pnpm config set registry https://registry.npmjs.org