Loading

前端项目修改npm/yarn配置文件来加速包下载

2022/01/25, .npmrc, .yarnrc

摘要:通过修改.npmrc/.yarnrc中registry镜像源来加速下载包

npm版

在项目根目录(package.json同一目录)中新建 .npmrc文件,编辑文件内容如下:

sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs/
electron_mirror=https://npm.taobao.org/mirrors/electron/
registry=https://registry.npm.taobao.org 

保存后再使用npm install下载包的速度会快很多

yarn版

在项目根目录(package.json同一目录)中新建 .yarnrc文件,编辑文件内容如下:

registry "https://registry.npm.taobao.org"

sass_binary_site "https://npm.taobao.org/mirrors/node-sass/"
phantomjs_cdnurl "http://cnpmjs.org/downloads"
electron_mirror "https://npm.taobao.org/mirrors/electron/"
sqlite3_binary_host_mirror "https://foxgis.oss-cn-shanghai.aliyuncs.com/"
profiler_binary_host_mirror "https://npm.taobao.org/mirrors/node-inspector/"
chromedriver_cdnurl "https://cdn.npm.taobao.org/dist/chromedriver"

保存后再使用yarn下载包的速度会快很多

直接修改全局配置

npm config set registry https://registry.npm.taobao.org --global
npm config set disturl https://npm.taobao.org/dist --global

npm i -g yarn
yarn config set registry https://registry.npm.taobao.org --global
yarn config set disturl https://npm.taobao.org/dist --global
posted @ 2022-01-25 23:07  kasnti  阅读(386)  评论(0编辑  收藏  举报