Packaging Your Application

    This is part 5 of the Electron tutorial.

    1. Prerequisites
    2. Using Preload Scripts
    3. Packaging Your Application

    In this part of the tutorial, we’ll be going over the basics of packaging and distributing your app with .

    Electron does not have any tooling for packaging and distribution bundled into its core modules. Once you have a working Electron app in dev mode, you need to use additional tooling to create a packaged app you can distribute to your users (also known as a distributable). Distributables can be either installers (e.g. MSI on Windows) or portable executable files (e.g. on macOS).

    Electron Forge is an all-in-one tool that handles the packaging and distribution of Electron apps. Under the hood, it combines a lot of existing Electron tools (e.g. , @electron/osx-sign, , etc.) into a single interface so you do not have to worry about wiring them all together.

    You can install Electron Forge’s CLI in your project’s devDependencies and import your existing project with a handy conversion script.

    • Yarn
    1. yarn add --dev @electron-forge/cli
    2. npx electron-forge import

    Once the conversion script is done, Forge should have added a few scripts to your package.json file.

    package.json

    CLI documentation

    For more information on make and other Forge APIs, check out the .

    Creating a distributable

    To create a distributable, use your project’s new make script, which runs the electron-forge make command.

    • npm
    • Yarn

    This make command contains two steps:

    1. It will first run electron-forge package under the hood, which bundles your app code together with the Electron binary. The packaged code is generated into a folder.
    2. It will then use this packaged app folder to create a separate distributable for each configured maker.

    After the script runs, you should see an out folder containing both the distributable and a folder containing the packaged application code.

    macOS output example

    1. out/
    2. ├── out/make/zip/darwin/x64/my-electron-app-darwin-x64-1.0.0.zip
    3. ├── ...
    4. └── out/my-electron-app-darwin-x64/my-electron-app.app/Contents/MacOS/my-electron-app

    The distributable in the out/make folder should be ready to launch! You have now created your first bundled Electron application.

    Packaging Your Application - 图3Distributable formats

    Electron Forge can be configured to create distributables in different OS-specific formats (e.g. DMG, deb, MSI, etc.). See Forge’s documentation for all configuration options.

    Creating and adding application icons

    Setting custom application icons requires a few additions to your config. Check out Forge’s icon tutorial for more information.

    If you want to manually package your code, or if you’re just interested understanding the mechanics behind packaging an Electron app, check out the full documentation.

    In order to distribute desktop applications to end users, we highly recommended for you to code sign your Electron app. Code signing is an important part of shipping desktop applications, and is mandatory for the auto-update step in the final part of the tutorial.

    Code signing is a security technology that you use to certify that a desktop app was created by a known source. Windows and macOS have their own OS-specific code signing systems that will make it difficult for users to download or launch unsigned applications.

    On macOS, code signing is done at the app packaging level. On Windows, distributable installers are signed instead. If you already have code signing certificates for Windows and macOS, you can set your credentials in your Forge configuration.

    Packaging Your Application - 图6info

    For more information on code signing, check out the guide in the Forge docs.

    • Windows

    forge.config.js

    forge.config.js

    1. module.exports = {
    2. makers: [
    3. {
    4. name: '@electron-forge/maker-squirrel',
    5. config: {
    6. certificateFile: './cert.pfx',
    7. certificatePassword: process.env.CERTIFICATE_PASSWORD,
    8. },
    9. },
    10. ],
    11. }

    Electron applications need to be packaged to be distributed to users. In this tutorial, you imported your app into Electron Forge and configured it to package your app and generate installers.