分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

node.js 模块和其下载资源的镜像设置

发布时间:2023-09-06 02:13责任编辑:蔡小小关键词:js

以前安装 electron 时总是失败,然后就在淘宝镜像上下载好相应版本的文件放到用户目录来解决问题。

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

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

1.环境变量

Unix:

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

Windows:

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

2.npm 执行参数

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

3.使用本地(项目根目录)或全局(用户目录).npmrc 配置

registry=https://registry.npm.taobao.orgelectron_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 模块和其下载资源的镜像设置

原文地址:https://www.cnblogs.com/gee1k/p/9597754.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved