Snapping Electron Applications with Electron-Packager

Create your project directory, with the following snap/snapcraft.yaml:

name: electron-packager-hello-world
version: '0.1'
summary: Hello World Electron app
description: |
  Simple Hello World Electron app as an example
base: core18
confinement: strict
grade: stable

apps:
  electron-packager-hello-world:
    command: electron-quick-start/electron-quick-start --no-sandbox
    extensions: [gnome-3-34]
    plugs:
    - browser-support
    - network
    - network-bind
    environment:
      # Correct the TMPDIR path for Chromium Framework/Electron to ensure
      # libappindicator has readable resources.
      TMPDIR: $XDG_RUNTIME_DIR

parts:
  electron-quick-start:
    plugin: nil
    source: https://github.com/electron/electron-quick-start.git
    override-build: |
        npm install electron electron-packager
        npx electron-packager . --overwrite --platform=linux --output=release-build --prune=true
        cp -rv ./electron-quick-start-linux-* $SNAPCRAFT_PART_INSTALL/electron-quick-start
    build-snaps:
    - node/14/stable
    build-packages:
    - unzip
    stage-packages:
    - libnss3
    - libnspr4

Build this snap with:

$ snapcraft

<output snipped>                                                                                                                                                                                                         
Snapped electron-packager-hello-world_0.1_amd64.snap

Install the snap with:

sudo snap install electron-packager-hello-world_0.1_amd64.snap --dangerous

Test it out with:

electron-packager-hello-world

We should really integrate this into the main Electron article. Electron packager is the only easy way (at the moment) to use things like a newer base or lzo compression. Also, great real-world examples like https://github.com/ogra1/mattermost-client/blob/master/snap/snapcraft.yaml are available.