npm、yarn、pnpm 设置最新国内镜像源(附官方镜像源和最新阿里源)

npm

查询源

BASH

npm get registry

设置源

BASH

国内 淘宝 镜像源

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

官方镜像源

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

pnpm

pnpm 的镜像源默认

查询源

BASH

pnpm get registry

设置源

BASH

国内 淘宝 镜像源

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

官方镜像源

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

yarn

查询源

BASH

yarn config get registry

设置源

BASH

国内 淘宝 镜像源

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

官方镜像源

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

镜像源集合

新增 华为、清华、网易 等镜像地址

请根据当前网络选择最佳镜像。

JSON

{

"npm": "https://registry.npmjs.org/",

"yarn": "https://registry.yarnpkg.com/",

"tencent": "https://mirrors.cloud.tencent.com/npm/",

"cnpm": "https://r.cnpmjs.org/",

"taobao": "https://registry.npmmirror.com/",

"npmMirror": "https://skimdb.npmjs.com/registry/",

"ali": "https://registry.npm.alibaba-inc.com/",

"huawei": "https://mirrors.huaweicloud.com/repository/npm/",

"163": "https://mirrors.163.com/npm/",

"ustc": "https://mirrors.ustc.edu.cn/",

"tsinghua": "https://mirrors.tuna.tsinghua.edu.cn/"

}

使用 nrm 切换镜像源

安装

BASH

npm install nrm -g

or

sudo npm install nrm -g

使用

nrm ls - 列出所有的镜像源或查看当前使用的源

BASH

nrm ls

nrm <add | del> <registry-name> [registry url] - 添加或删除镜像源

BASH

添加源

nrm add testRegistry https://baidu.com/

删除源

nrm del testRegistry

nrm use <registry-name> - 使用源

BASH

nrm use taobao

nrm test - 测试所有镜像源的速度

BASH

nrm test

总结

清除缓存

BASH

npm cache clean --force

设置后 yarn 不生效?

yarn 版本 1.22.22

yarn 并未读取当前 项目目录 或用户(~/.npmrc)目录下的 .npmrc 文件的 registry 字段,在查询 yarn v1 官网和相关 issue(https://github.com/yarnpkg/yarn/issues/2118)未发现相关描述

yarn v1.x 版本中仍会读取 .npmrc 的相关字段,但会优先使用 .yarnrc 中的值,由于 yarn config 中的 registry 字段无法删除(delete 后仍有默认值),在项目外只能使用命令更改,或修改 .yarnrc。至于未读取当前项目下的 .npmrc 中的 registry 暂未知。

nrm use 时做了什么?

可以看出 nrm 更改的是 ~/.npmrc 文件

https://npmmirror.com/

推荐文章

作者: kshao

链接: https://ksh7.com/posts/npm-registry/index.html#清除缓存

来源: kshao-blog-前端知识记录

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

相关推荐
北辰alk40 分钟前
Vue3 自定义指令深度解析:从基础到高级应用的完整指南
前端·vue.js
AAA阿giao40 分钟前
使用 Vite + Vue 3 搭建项目并配置路由的全流程(含国内镜像加速)
vue.js·node.js·vite
北辰alk1 小时前
Vue3 异步组件深度解析:提升大型应用性能与用户体验的完整指南
前端·vue.js
qq_366577512 小时前
Vue3创建项目,只能localhost访问问题处理
前端·javascript·vue.js
笨笨狗吞噬者3 小时前
【uniapp】小程序实现自由控制组件JSON文件配置
vue.js·微信小程序·vite
龙国浪子3 小时前
小说写作软件中的文本高亮功能:基于 TipTap 的多彩标记技术实现
vue.js·electron
武昌库里写JAVA4 小时前
Java如何快速入门?Java基础_Java入门
java·vue.js·spring boot·后端·sql
Irene19914 小时前
Element UI 及其 Vue 3 版本 Element Plus 发展现状
前端·vue.js·ui
Account_Ray4 小时前
vue3 的专属二维码组件 vue3-next-qrcode 迎来 4.0.0 版本
前端·vue.js·nuxt.js
帧栈4 小时前
开发避坑指南(70):Vue3 Http请求头携带token下载pdf文件解决方案
前端·vue.js