前端Linux

Electron - 跨平台发布之Ubuntu

2021-07-08  本文已影响0人  红薯爱帅

1. 概述

本文介绍怎么在Ubuntu20.04系统下,完成Electron项目的开发和发布。

2. 开发环境准备

2.1. update apt source with proxy

如果你不需要proxy可以直接访问外网,可以跳过此步

$ sudo vi /etc/apt/apt.conf
Acquire::http::Proxy "http://user:pass@proxy_host:port";
$ export http_proxy=http://user:pass@proxy_host:port
$ sudo apt update

参考:https://www.unixmen.com/45713-2/

2.2. change apt source list

$ sudo vi /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
$ sudo apt update

参考:https://blog.csdn.net/xiangxianghehe/article/details/105688062

2.3. install common soft

$ sudo apt install openssh-server tmux git vim net-tools -y

2.4. install nodejs environment

$ apt install nodejs npm -y

$ npm config set registry https://registry.npm.taobao.org
$ npm config list

$ vim /etc/bash.bashrc
export http_proxy=http://10.251.175.152:8000
export https_proxy=http://10.251.175.152:8000
export no_proxy=localhost,10.0.0.0/8,127.0.0.1,::1
$ source /etc/bash.bashrc

$ npm install -g n yarn
$ n i 14
$ n list
node/14.17.3
$ node -v
v14.17.3
$ yarn -v
1.22.10

2.5. 补充说明

以下是npm config关于proxy的说明,会默认系统的env,所以理论上,配好系统proxy的env就好

关于no_proxy的配置

10.*可能只在部分场景可用,例如浏览器Proxy和Windows系统Proxy

Cygwin64Ubuntu20系统,需要用10.0.0.0/8,否则,你会一直纠结。。。

export no_proxy=localhost,10.0.0.0/8,127.0.0.1,::1

3. Build and Release

3.1. build your electron app

$ npx cross-env ELECTRON_GET_USE_PROXY=true GLOBAL_AGENT_HTTPS_PROXY=http://10.251.175.152:8000 yarn
$ yarn dev
$ yarn build
$ yarn release

3.2. publish

"build": {
    "linux": {
      "icon": "build/icons/fox.png",
      "category": "Network",
      "artifactName": "${productName}-${os}-${arch}-${version}-setup.${ext}",
      "target": ["AppImage", "deb", "tar.gz"],
      "maintainer": "Shuzhang"
    },
}

3.3. auto-update

linux下build,如果target不写AppImage,而是其他,例如deb,会有两个问题:

if (process.platform !== 'linux' || process.env.APPIMAGE) {
    updateHandle()
}

相关Issues:

3.4. Errors

上传或下载文件时,出现上述错误,需要修改系统时间为当前时间

看一下html内容,如果是被网关拦截,说明noproxy配置有问题

4. Build Servers

上述发布方式,需要login到ubuntu机器,执行相关命令才能release。

如何在Windows上build其他主流OS的installer,electron-builder也给了解决办法,采用docker的方式。

Note: Don’t expect that you can build app for all platforms on one platform.
https://www.electron.build/multi-platform-build

4.1. Provided Docker Images

4.2. Electron Build Service

Free public Electron Build Service is used to build Electron app for Linux on Windows.
To deploy, kubernetes is used for security reasons. Linux is required, but you can use multipass to run on macOS/Windows.

Two steps to setup:

4.3. Travis

Travis to build macOS/Linux apps

https://www.electron.build/multi-platform-build#sample-travisyml-to-build-electron-app-for-macos-linux-and-windows

4.4. AppVeyor

AppVeyor to build Windows app

https://www.electron.build/multi-platform-build#sample-appveyoryml-to-build-electron-app-for-windows

5. 下一步计划

Electron跨平台支持,还需要

上一篇下一篇

猜你喜欢

热点阅读