Snapcraft 指南 (Linux)
本指南提供了有关如何包装你的 Electron 应用程序的任何 Snapcraft 环境, 包括 Ubuntu 软件中心的信息。
背景和要求
与更广泛的 Linux 社区一起, 规范旨在解决 snapcraft
项目中的许多常见的软件安装问题。 Snaps 是容器化的软件包, 包括所需的依赖项、自动更新和对所有主要 Linux 发行版的工作, 而无需进行系统修改。
创建 .snap
文件有三种方法:
- 使用 Electron Forge或
electron-builder
,这两个工具都提供snap
开箱即用支持 这是最简单的选择。 2) Usingelectron-installer-snap
, which takes@electron/packager
's output. 3) 使用已经创建的.deb
包。
在某些情况下,您需要安装 snapcraft
工具。 安装特定发行版的 snapcraft
的指南在这里能看到。
使用 electron-installer-snap
The module works like electron-winstaller
and similar modules in that its scope is limited to building snap packages. 你可以这样安装:
npm install --save-dev electron-installer-snap
步骤 1: 打包你的 Electron 应用程序
Package the application using @electron/packager (or a similar tool). 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.
结构输出应该看起来大致像这样:
.
└── dist
└── app-linux-x64
├── LICENSE
├── LICENSES.chromium.html
├── content_shell.pak
├── app
├── icudtl.dat
├── libgcrypt.so.11
├── libnode.so
├── locales
├── resources
├── v8_context_snapshot.bin
└── version
步骤 2: 运行 electron-installer-snap
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
If you have an existing build pipeline, you can use electron-installer-snap
programmatically. For more information, see the Snapcraft API docs.
const snap = require('electron-installer-snap')
snap(options)
.then(snapPath => console.log(`Created snap at ${snapPath}!`))