electron-vite 安装, 打包下载资源失败,设置国内镜像

发布时间 2024-01-09 19:33:14作者: 兔&&大梅

由于electron默认打包会从github上下载相关二进制包,众所周知,国内GitHub访问是相当慢的,所以经常会出现下载失败导致打包不成功,这时我们就需要配置国内的镜像源,以解决从GitHub下载慢甚至无法下载的问题。

修改npm配置文件(没有就创建):

npm的配置文件为用户根目录下的:~/.npmrc(Windows路径为:C:\Users<UserName>.npmrc)

加入以下内容:

prefix=/opt/node/global
cache=/opt/node/cache
registry=https://registry.npmmirror.com/
disturl=https://registry.npmmirror.com/-/binary/node/
sass_binary_site=https://registry.npmmirror.com/node-sass
phantomjs_cdnurl=https://registry.npmmirror.com/phantomjs
chromedriver_cdnurl=https://registry.npmmirror.com/-/binary/chromedriver/
operadriver_cdnurl=https://registry.npmmirror.com/-/binary/operadriver/
electron_mirror=https://registry.npmmirror.com/-/binary/electron/
electron_builder_binaries_mirror=https://registry.npmmirror.com/-/binary/electron-builder-binaries/
always-auth=false

  


其中prefix是全局包 的路径,cache是缓存路径,这两个可以不配置。

这样再打包就不会报错了。
打包以下错误,要以管理员去运行 build