Snapcraft 指南 (Ubuntu 软件中心 & 更多)
与更广泛的 Linux 社区一起, 规范旨在解决 snapcraft
项目中的许多常见的软件安装问题。 Snaps 是容器化的软件包, 包括所需的依赖项、自动更新和对所有主要 Linux 发行版的工作, 而无需进行系统修改。
创建 .snap
文件有三种方法:
1) 使用 或 electron-builder
, 与 snap
支持的两个工具都不在该框中。 这是最简单的选择。 2) 使用 electron-installer-snap
, 它采用 electron-packager
的输出。 3) 使用已经创建的 .deb
包。
In all cases, you will need to have the snapcraft
tool installed. We recommend building on Ubuntu 16.04 (or the current LTS).
该模块的工作原理与类似 因为它的范围仅限于构建捕捉包。 你可以这样安装:
npm install --save-dev electron-installer-snap
打包应用程序使用 electron-packager (或类似工具)。 Make sure to remove node_modules
that you don’t need in your final application, since any module you don’t actually need will increase your application’s size.
结构输出应该看起来大致像这样:
From a terminal that has snapcraft
in its PATH
, run electron-installer-snap
with the only required parameter --src
, which is the location of your packaged Electron application created in the first step.
npx electron-installer-snap --src=out/myappname-linux-x64
Snapcraft is capable of taking an existing .deb
file and turning it into a .snap
file. The creation of a snap is configured using a snapcraft.yaml
file that describes the sources, dependencies, description, and other core building blocks.
If you do not already have a package, using electron-installer-snap
might be an easier path to create snap packages. However, multiple solutions for creating Debian packages exist, including , electron-builder
or .
For more information on the available configuration options, see the documentation on the snapcraft syntax. Let’s look at an example:
name: myApp
version: '2.0.0'
summary: A little description for the app.
description: |
You know what? This app is amazing! It does all the things
for you. Some say it keeps you young, maybe even happy.
grade: stable
parts:
slack:
plugin: dump
source: my-deb.deb
source-type: deb
after:
- desktop-gtk3
stage-packages:
- libasound2
- libnotify4
- libnspr4
- libnss3
- libpulse0
- libxss1
- libxtst6
plugin: dump
source: files/
prepare: |
chmod +x bin/electron-launch
apps:
myApp:
command: bin/electron-launch $SNAP/usr/lib/myApp/myApp
desktop: usr/share/applications/myApp.desktop
# Correct the TMPDIR path for Chromium Framework/Electron to ensure
# libappindicator has readable resources.
environment:
TMPDIR: $XDG_RUNTIME_DIR
As you can see, the snapcraft.yaml
instructs the system to launch a file called electron-launch
. In this example, it passes information on to the app’s binary:
apps:
myApp:
# Correct the TMPDIR path for Chromium Framework/Electron to ensure
# libappindicator has readable resources.
desktop: usr/share/applications/desktop.desktop