Snapcraft Guide (Linux)

    与更广泛的 Linux 社区一起, 规范旨在解决 snapcraft 项目中的许多常见的软件安装问题。 Snaps 是容器化的软件包, 包括所需的依赖项、自动更新和对所有主要 Linux 发行版的工作, 而无需进行系统修改。

    创建 .snap 文件有三种方法:

    1) 使用 或 electron-builder, 与 snap 支持的两个工具都不在该框中。 这是最简单的选择。 2) 使用 electron-installer-snap, 它采用 electron-packager 的输出。 3) 使用已经创建的 .deb 包。

    在某些情况下,您需要安装 snapcraft 工具。 安装特定发行版的 snapcraft 的指南能看到。

    打包应用程序使用 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.

    结构输出应该看起来大致像这样:

    1. .
    2. └── dist
    3. └── app-linux-x64
    4. ├── LICENSE
    5. ├── LICENSES.chromium.html
    6. ├── content_shell.pak
    7. ├── app
    8. ├── icudtl.dat
    9. ├── libgcrypt.so.11
    10. ├── libnode.so
    11. ├── locales
    12. ├── resources
    13. ├── v8_context_snapshot.bin
    14. └── 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.

    1. 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.

    1. name: electron-packager-hello-world
    2. version: '0.1'
    3. summary: Hello World Electron app
    4. description: |
    5. Simple Hello World Electron app as an example
    6. base: core18
    7. confinement: strict
    8. grade: stable
    9. apps:
    10. electron-packager-hello-world:
    11. extensions: [gnome-3-34]
    12. plugs:
    13. - browser-support
    14. - network
    15. - network-bind
    16. environment:
    17. # Correct the TMPDIR path for Chromium Framework/Electron to ensure
    18. # libappindicator has readable resources.
    19. TMPDIR: $XDG_RUNTIME_DIR
    20. parts:
    21. electron-quick-start:
    22. plugin: nil
    23. source: https://github.com/electron/electron-quick-start.git
    24. override-build: |
    25. npm install electron electron-packager
    26. npx electron-packager . --overwrite --platform=linux --output=release-build --prune=true
    27. cp -rv ./electron-quick-start-linux-* $SNAPCRAFT_PART_INSTALL/electron-quick-start
    28. build-snaps:
    29. - node/14/stable
    30. build-packages:
    31. - unzip
    32. stage-packages:
    33. - libnss3
    34. - libnspr4

    如果要将此示例应用于现有项目:

    • 替代 source: https://github.com/electron/electron-quick-start.git</0 > 为 <code>source: ...
    • 替代所有的 electron-quick-start 为你的项目名称。

    第 2 步:构建 snap

    1. $ snapcraft
    2. <output snipped>
    3. Snapped electron-packager-hello-world_0.1_amd64.snap

    第 4 步:运行 snap

    1. electron-packager-hello-world

    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 .deb 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 .

    步骤 2: 创建一个 snapcraft.yaml

    For more information on the available configuration options, see the . Let’s look at an example:

    1. name: myApp
    2. version: '2.0.0'
    3. summary: A little description for the app.
    4. description: |
    5. for you. Some say it keeps you young, maybe even happy.
    6. grade: stable
    7. confinement: classic
    8. parts:
    9. slack:
    10. plugin: dump
    11. source: my-deb.deb
    12. source-type: deb
    13. after:
    14. - desktop-gtk3
    15. stage-packages:
    16. - libasound2
    17. - libnotify4
    18. - libnspr4
    19. - libnss3
    20. - libpcre3
    21. - libpulse0
    22. - libxss1
    23. - libxtst6
    24. electron-launch:
    25. plugin: dump
    26. source: files/
    27. prepare: |
    28. chmod +x bin/electron-launch
    29. apps:
    30. myApp:
    31. command: bin/electron-launch $SNAP/usr/lib/myApp/myApp
    32. desktop: usr/share/applications/myApp.desktop
    33. # Correct the TMPDIR path for Chromium Framework/Electron to ensure
    34. # libappindicator has readable resources.
    35. environment:
    36. TMPDIR: $XDG_RUNTIME_DIR

    Alternatively, if you’re building your snap with strict confinement, you can use the desktop-launch command:

    1. apps:
    2. myApp:
    3. # Correct the TMPDIR path for Chromium Framework/Electron to ensure
    4. # libappindicator has readable resources.