npm国内镜像加速
在使用npm过程中经常会遇到无法下载包的问题,本人在这里整理了几个npm使用国内镜像加速的方法,希望对大家有所帮助。
一、修改成腾讯云镜像源#
1、命令
npm config set registry http://mirrors.cloud.tencent.com/npm/
- 验证命令
npm config get registry
如果返回 http://mirrors.cloud.tencent.com/npm/ ,说明镜像配置成功。
二、修改成淘宝镜像源#
- 命令
npm config set registry https://registry.npmmirror.com
- 验证命令
npm config get registry
如果返回 https://registry.npmmirror.com ,说明镜像配置成功。
三、修改成华为云镜像源#
- 命令
npm config set registry https://mirrors.huaweicloud.com/repository/npm/
- 验证命令
npm config get registry
如果返回 https://mirrors.huaweicloud.com/repository/npm/ ,说明镜像配置成功。
四、通过使用淘宝定制的cnpm安装#
- 安装cnpm
npm install -g cnpm --registry=https://registry.npmmirror.com
- 使用cnpm
cnpm install xxx
# https://github.com/cnpm/binary-mirror-config/blob/master/package.json#L53
export NODEJS_ORG_MIRROR="https://cdn.npmmirror.com/binaries/node"
export NVM_NODEJS_ORG_MIRROR="https://cdn.npmmirror.com/binaries/node"
export PHANTOMJS_CDNURL="https://cdn.npmmirror.com/binaries/phantomjs"
export CHROMEDRIVER_CDNURL="https://cdn.npmmirror.com/binaries/chromedriver"
export OPERADRIVER_CDNURL="https://cdn.npmmirror.com/binaries/operadriver"
export ELECTRON_MIRROR="https://cdn.npmmirror.com/binaries/electron/"
export ELECTRON_BUILDER_BINARIES_MIRROR="https://cdn.npmmirror.com/binaries/electron-builder-binaries/"
export SASS_BINARY_SITE="https://cdn.npmmirror.com/binaries/node-sass"
export SWC_BINARY_SITE="https://cdn.npmmirror.com/binaries/node-swc"
export NWJS_URLBASE="https://cdn.npmmirror.com/binaries/nwjs/v"
export PUPPETEER_DOWNLOAD_HOST="https://cdn.npmmirror.com/binaries"
export SENTRYCLI_CDNURL="https://cdn.npmmirror.com/binaries/sentry-cli"
export SAUCECTL_INSTALL_BINARY_MIRROR="https://cdn.npmmirror.com/binaries/saucectl"
export npm_config_sharp_binary_host="https://cdn.npmmirror.com/binaries/sharp"
export npm_config_sharp_libvips_binary_host="https://cdn.npmmirror.com/binaries/sharp-libvips"
export npm_config_robotjs_binary_host="https://cdn.npmmirror.com/binaries/robotj"
# For Cypress >=10.6.0, https://docs.cypress.io/guides/references/changelog#10-6-0
export CYPRESS_DOWNLOAD_PATH_TEMPLATE='https://cdn.npmmirror.com/binaries/cypress/${version}/${platform}-${arch}/cypress.zip'