小知识,大挑战!本文正在参与“程序员必备小知识”创作活动。
此前介绍了 nrm 用于快速切换 NPM 镜像源。
最原始设置 npm、yarn 镜像源的方式如下:
# use npm
$ npm config set registry <registry-url>
# use yarn
$ yarn config set registry <registry-url>
使用 nrm 更方便:
# nrm use taobao
$ nrm use <registry>
但是这个有点不爽,就是说它只会切换 npm 命令的镜像源,nrm 无法修改 yarn 的。
最近发现了一个 i5ting/yrm(YARN registry manager)工具,可以同步修改 npm 和 yarn 镜像源,它本身也是 nrm 的一个 Fork 分支。
# install
$ npm i yrm -g
# switch registry
$ yrm use <registry>
# ...
使用方法与 nrm 一致,可以通过 -h 查看帮助。
$ yrm -h
Usage: yrm [options] [command]
Options:
-V, --version output the version number
-h, --help output usage information
Commands:
ls List all the registries
current Show current registry name
use <registry> Change registry to registry
add <registry> <url> [home] Add one custom registry
del <registry> Delete one custom registry
home <registry> [browser] Open the homepage of registry with optional browser
test [registry] Show response time for specific or all registries
help Print this help
当你使用其他非预设注册表时,不能使用
publish命令。通常我发布 NPM 包都是直接使用npm public命令。
效果如下:
$ yrm use taobao
YARN Registry has been set to: https://registry.npm.taobao.org/
NPM Registry has been set to: https://registry.npm.taobao.org/
「重要通知」原淘宝 npm 域名即将停止解析,请切换至新域名 npmmirror.com,
http://npm.taobao.org和http://registry.npm.taobao.org将在 2022.06.30 号正式下线和停止 DNS 解析。
由于 yrm 包最新一次更新还是五年前,因此淘宝镜像的域名还是旧域名,可以通过以下方式进行更新:
$ yrm add taobao https://registry.npmmirror.com/
参考链接: