npm、yarn、pnpm 设置最新国内镜像源

1. npm 设置国内镜像源

npm 官方提供了多个国内镜像源,最常用的是淘宝的 npm 镜像。可以通过以下命令设置:

使用淘宝镜像

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

查看当前镜像源
在更改之前,你可以查看当前的镜像源:

npm config get registry

恢复到官方源
如果需要恢复到默认的 npm 官方源,可以使用以下命令:

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

2. yarn 设置国内镜像源

对于 yarn,可以通过命令行设置镜像源,通常也是使用淘宝镜像:

使用淘宝镜像

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

查看当前镜像源
你可以查看当前的镜像源配置:

yarn config get registry

恢复到官方源
若要恢复到 yarm 的默认源,可以使用:

yarn config delete registry

3. pnpm 设置国内镜像源

pnpm 也支持设置镜像源,同样使用淘宝镜像进行加速:

使用淘宝镜像

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

查看当前镜像源
若想查看当前的镜像源,可以执行:

扫描二维码关注公众号,回复: 17480175 查看本文章
pnpm get config registry

恢复到官方源
若需恢复到默认的官方源,可以运行:

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