npm、yarn、pnpm 设置国内源。
# 镜像源
国内可用的镜像源主要有淘宝镜像、腾讯云镜像,虽然都会同步官方 npm 源的包,但是会存在一些延迟。如果是不常用的包(比如自己发布的包)延迟会比较大。
从使用情况来看淘宝镜像源速度较快。
# 淘宝镜像源
https://registry.npmmirror.com/
# 腾讯云镜像源
https://mirrors.cloud.tencent.com/npm/
# 设置镜像源
# npm
# 查询当前使用的镜像源 | |
npm get registry | |
# 设置为淘宝镜像源 | |
npm config set registry https://registry.npmmirror.com/ | |
# 还原为官方镜像源 | |
npm config set registry https://registry.npmjs.org/ |
# pnpm
# 查询当前使用的镜像源 | |
pnpm get registry | |
# 设置为淘宝镜像源 | |
pnpm config set registry https://registry.npmmirror.com/ | |
# 还原为官方镜像源 | |
pnpm config set registry https://registry.npmjs.org/ |
# yarn
# 查询当前使用的镜像源 | |
yarn config get registry | |
# 设置为淘宝镜像源 | |
yarn config set registry https://registry.npmmirror.com/ | |
# 还原为官方镜像源 | |
yarn config set registry https://registry.yarnpkg.com/ |