目录
1. 背景
2. npm
2.1. 配置镜像源
2.2. 配置代理
3. yarn
3.1. 配置镜像源
3.2. 配置代理
1. 背景
换npm、yarn的镜像源,或配置npm、yarn的代理,都是为了解决 npm 依赖下载慢的问题。
2. npm
2.1. 配置镜像源
// 查看镜像源
npm config get registry
// 设置镜像源
npm config set registry http://registry.npm.taobao.org/
npm config set registry https://registry.npmjs.org/
npm install -g nrm // 安装
nrm ls // 查看已有的源
nrm use <registry> // 切换源
nrm add <registry> <url> // 添加源
nrm del <registry> // 删除源
nrm test [registry] // 测速
2.2. 配置代理
// 查看代理
npm config get proxy
npm config get https-proxy
// 设置代理
npm config set proxy http://127.0.0.1:8080
npm config set https-proxy http://127.0.0.1:8080
// 删除代理
npm config delete proxy
npm config delete https-proxy
3. yarn
3.1. 配置镜像源
// 查看镜像源
yarn config get registry
// 设置镜像源
yarn config set registry http://registry.npm.taobao.org/
yarn config set registry https://registry.npmjs.org/
3.2. 配置代理
// 查看代理
yarn config get proxy
yarn config get https-proxy
// 设置代理
yarn config set proxy http://127.0.0.1:8080
yarn config set https-proxy http://127.0.0.1:8080
// 删除代理
yarn config delete proxy
yarn config delete https-proxy
参考:
NPM registry manager(nrm): https://github.com/Pana/nrm npm Docs: https://docs.npmjs.com/cli/v6/using-npm/config#proxy https://docs.npmjs.com/cli/v6/using-npm/config#https-proxy