溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

如何設(shè)置node.js模塊和其下載資源的鏡像

發(fā)布時間:2021-07-30 13:41:19 來源:億速云 閱讀:131 作者:小新 欄目:web開發(fā)

這篇文章將為大家詳細(xì)講解有關(guān)如何設(shè)置node.js模塊和其下載資源的鏡像,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

后來研究發(fā)現(xiàn) npm 不僅可以設(shè)置 node.js 模塊倉庫的代理, 同樣可以設(shè)置像 electron、phantomjs、 node-sass 等模塊的鏡像代理

一、設(shè)置淘寶鏡像 (共三種方法)

1.環(huán)境變量

Unix:

# electron
export ELECTRON_MIRROR=https://npm.taobao.org/mirrors/electron/
# phantomjs
export PHANTOMJS_CDNURL=https://npm.taobao.org/mirrors/phantomjs/
# node-sass
export SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/

Windows:

# electron
set ELECTRON_MIRROR=https://npm.taobao.org/mirrors/electron/
# phantomjs
set PHANTOMJS_CDNURL=https://npm.taobao.org/mirrors/phantomjs/
# node-sass
set SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/

2.npm 執(zhí)行參數(shù)

# electron
npm install electron --electron-mirror=https://npm.taobao.org/mirrors/electron/
# phantomjs
npm install phantomjs --phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs/
# node-sass
npm install node-sass --sass-binary-site=https://npm.taobao.org/mirrors/node-sass/

3.使用本地(項目根目錄)或全局(用戶目錄).npmrc 配置

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

二、使用代理

除了使用代理來解決,更暴力直接的方法就是使用梯子了。

 確保你要安裝的模塊倉庫地址在代理PAC列表中或直接使用全局代理。npm 好像只支持 HTTP 代理

# 設(shè)置代理
npm config set proxy http://127.0.0.1:1085
# 安裝模塊
npm i --save-dev electron
# 刪除代理
npm config delete proxy

關(guān)于“如何設(shè)置node.js模塊和其下載資源的鏡像”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI