重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

如何设置node.js模块和其下载资源的镜像-创新互联

这篇文章将为大家详细讲解有关如何设置node.js模块和其下载资源的镜像,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

创新互联建站是一家专注网站建设、网络营销策划、微信小程序定制开发、电子商务建设、网络推广、移动互联开发、研究、服务为一体的技术型公司。公司成立十年以来,已经为上千多家混凝土搅拌机各业的企业公司提供互联网服务。现在,服务的上千多家客户与我们一路同行,见证我们的成长;未来,我们一起分享成功的喜悦。

后来研究发现 npm 不仅可以设置 node.js 模块仓库的代理, 同样可以设置像 electron、phantomjs、 node-sass 等模块的镜像代理

一、设置淘宝镜像 (共三种方法)

1.环境变量

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 执行参数

# 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 代理

# 设置代理
npm config set proxy http://127.0.0.1:1085
# 安装模块
npm i --save-dev electron
# 删除代理
npm config delete proxy

关于“如何设置node.js模块和其下载资源的镜像”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。


文章题目:如何设置node.js模块和其下载资源的镜像-创新互联
浏览地址:http://cqcxhl.com/article/dgeooc.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP