npm/pnpm/yarn 安装镜像加速
众所周知的原因,国内的网络环境下,npm、pnpm、yarn 等包管理器的下载速度非常慢。我们可以通过修改 npm 源来解决这个问题。
查看当前的 npm 源
# 查看当前的 npm 源
npm config get registry
# 查看当前的 pnpm 源
pnpm config get registry
# 查看所有的 yarn 源
yarn config get registry
顺便学习一下查看配置的命令
# 查看所有的 yarn 配置
yarn config list
# 查看所有的 pnpm 配置
pnpm config list
# 查看所有的 npm 配置
npm config list
通过命令行直接修改 npm 源
# 修改 npm 源 为淘宝镜像
npm config set registry https://registry.npmmirror.com
# 修改 pnpm 源
pnpm config set registry https://registry.npmmirror.com
# 修改 yarn 源
yarn config set registry https://registry.npmmirror.com
查看修改后的 npm 源
npm config get registry
# 如果修改成功,输出的是 https://registry.npmmirror.com
另外一种方法:通过修改 npm/pnpm/yarn 的配置文件来修改 npm 源
另外,你也可以通过修改 ~/.npmrc 或者 ~/.yarnrc 或者 ~/.pnpmrc 来修改 npm 源。
参考代码:
# ~/.npmrc
registry=https://registry.npmmirror.com
还原默认的 npm 源
npm config set registry https://registry.npmjs.org
pnpm config set registry https://registry.npmjs.org
yarn config set registry https://registry.npmjs.org