nodejs学习03——包管理工具npm

发布时间 2023-11-13 17:03:58作者: htj10

关于npm的国内镜像源

一、说明

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

二、NPM切换镜像源

  1. 查看当前的镜像源。
npm config get registry
  1. 设置为淘宝源
npm config set registry https://registry.npm.taobao.org
  1. 还原默认源
npm config set registry https://registry.npmjs.org/
  1. 临时使用
    上面那种设置是全局的,以后每次都会自动读取已经设置好的源,如果只是一次性使用,可以使用下面的命令
npm --registry https://registry.npm.taobao.org install XXX(模块名)

  1. 使用cnpm
    cnpm是一个命令,用它来代替npm
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install XXX(模块名)
  1. 使用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

————————————————
版权声明:本文为CSDN博主「一枚码农404」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u012970287/article/details/131100890