npm、yarn、pnpm切源

包管理工具切换源

为何要切换 npm、yarn、pnpm 源?

由于默认的 npm,yarn 源是国外,访问速度很慢,因此选择国内镜像,加快下载安装速度,eg:切换为淘宝源或者公司内部源

  • pnpm

    performant npm 高效能 npm
    pnpm store prune 删除 store 中不再引用的包

npm 如何切换源?

切换源 Registry 的 4 种方式

  • 全局注册 Global registry
    通过设置 config 来设置 Global registry 源
# npm、pnpm
npm config set registry https://registry.npmmirror.com
pnpm config set registry https://registry.npmmirror.com
yarn config set registry https://registry.npmmirror.com
  • .npmrc
    在项目根目录创建.npmrc 文件,npm,pnpm 在安装下载包时,会默认读取文件配置
registry = https://registry.npmmirror.com
sentrycli_cdnurl=https://npmmirror.com/mirrors/sentry-cli
SENTRYCLI_CDNURL=https://npmmirror.com/mirrors/sentry-cli
  npm install -g nrm
  nrm ls
  // 添加一个源
  nrm add test https://xxxx
  nrm use taobao

源配置优先级

项目配置 > 用户配置 > 全局配置

pnpm 安装包命令

// 安装最新包
pnpm up -r @xxx/antd-ui -L

pnpm up -r @xxx/jsbridge -L

注意:这样安装会出现把相关的依赖包都更新版本的问题存在

posted @ 2023-03-30 17:12  晚安喵  阅读(1162)  评论(0编辑  收藏  举报