Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Electron Packaging and Distribution

Electron Packaging and Distribution

After an Electron app is developed, it needs to be packaged into a desktop executable and released to users.

The packaging and distribution process involves tool selection, configuration, signing, update strategies, and more.


Packaging tool introduction

electron-builder

electron-packager

electron-forge

Tool comparison and selection

Tool Feature Advantage Applicable scenarios
electron-builder High automation, cross-platform, supports updates Simple configuration, suitable for production Complex application release
electron-packager Lightweight, officially supported Flexible combination with other tools Simple application packaging
electron-forge Integrated development tools, quick start Works out of the box, built-in build Beginners or rapid prototyping

Configuring packaging parameters

package.json configuration

"build": {

  "appId": "com.example.myapp",

  "productName": "MyElectronApp",

  "directories": {

    "output": "dist"

  },

  "files": ["**/*"],

  "extraResources": ["assets/"],

  "mac": {

    "category": "public.app-category.utilities"

  },

  "win": {

    "target": "nsis",

    "icon": "build/icon.ico"

  },

  "linux": {

    "target": ["AppImage", "deb"],

    "icon": "build/icon.png"

  }

}

Platform-specific configuration

Icon and resource files


Multi-platform packaging

Windows packaging

electron-builder --win

macOS packaging

electron-builder --mac

Linux packaging

electron-builder --linux

Cross compilation


Code signing

Windows code signing

electron-builder --win --csc-link path/to/certificate.pfx --csc-key-password yourpassword

macOS notarization



electron-builder --mac --publish never

Certificate application and management


Automatic updates

Using electron-updater

Main process example:

const { autoUpdater } = require('electron-updater')



autoUpdater.on('update-available', () => console.log('发现新版本'))

autoUpdater.on('update-downloaded', () => autoUpdater.quitAndInstall())

autoUpdater.checkForUpdates()

Setting up an update server

Differential updates

Update strategy


Summary

Core workflow of Electron packaging and distribution:

Following best practices lets Electron apps be distributed to users quickly and safely, while making future iteration and updates easier.