0Pricing
Electron Desktop App Development · Lesson

Cross-Platform Packaging

Master advanced packaging options and configurations using `electron-builder` for robust cross-platform distribution.

Cross-Platform Packaging is a free Electron Desktop App Development lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Electron Desktop App Development learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What is Cross-Platform Packaging?

When you build an Electron application, you're creating a desktop app using web technologies. To distribute this app to users, you need to package it into an executable or installer specific to their operating system.

Cross-platform packaging means creating these distribution files for Windows, macOS, and Linux from a single codebase. This ensures your app can reach a wide audience regardless of their chosen OS.

Introducing electron-builder

electron-builder is the go-to solution for packaging and distributing Electron applications. It's a powerful and flexible tool that automates much of the complex process.

  • Generates installers: Creates `.exe`, `.dmg`, `.deb`, `.AppImage`, and more.
  • Code signing: Handles signing for security and trust.
  • Auto-updates: Integrates with auto-update mechanisms.
  • Flexible configuration: Highly customizable through your package.json file or external configuration.

Basic electron-builder Setup

To get started, you'll install electron-builder as a development dependency and add a "build" script to your package.json. This script typically points to the electron-builder command.

Here's a basic setup:

{
  "name": "my-electron-app",
  "version": "1.0.0",
  "main": "main.js",
  "scripts": {
    "start": "electron .",
    "build": "electron-builder"
  },
  "devDependencies": {
    "electron": "^28.0.0",
    "electron-builder": "^24.0.0"
  },
  "build": {
    "appId": "com.yourapp.id"
  }
}

Understanding "appId"

The appId (Application ID) is a crucial identifier for your application. It's a unique string, often in reverse domain name format (e.g., com.yourcompany.yourappname).

  • Uniqueness: Helps operating systems identify your app.
  • Updates: Essential for distinguishing your app during updates.
  • Data storage: Used by OS for application-specific data.

Always use a unique appId for your application.

Windows-Specific Configurations

For Windows, electron-builder can generate different installer types. The most common are NSIS (Nullsoft Scriptable Install System) and Squirrel.Windows.

  • NSIS: Creates traditional `.exe` installers, offering more customization.
  • Squirrel.Windows: Provides easy auto-updates and a simpler installation experience.

You can define Windows-specific settings under the "win" key in your "build" configuration.

Windows Config Example

Here's how you might configure `electron-builder` for Windows, specifying targets and an icon:

{
  "name": "my-electron-app",
  "build": {
    "appId": "com.yourapp.id",
    "win": {
      "target": [
        "nsis",
        "squirrel"
      ],
      "icon": "build/icon.ico"
    }
  }
}

macOS-Specific Configurations

On macOS, the primary distribution formats are DMG (Disk Image) and PKG (Installer Package). `electron-builder` handles the specifics for these.

  • DMG: The most common way to distribute macOS apps, allowing drag-and-drop installation.
  • PKG: A traditional installer package, suitable for more complex installations or enterprise distribution.

Crucial macOS settings include category and bundleId (which should match your appId).

macOS Config Example

This snippet shows macOS-specific settings, including targets, bundle ID, and application category:

{
  "name": "my-electron-app",
  "build": {
    "appId": "com.yourapp.id",
    "mac": {
      "target": [
        "dmg",
        "pkg"
      ],
      "category": "public.app-category.developer-tools",
      "bundleId": "com.yourapp.id",
      "icon": "build/icon.icns"
    }
  }
}

Linux-Specific Configurations

Linux has a variety of package formats. electron-builder supports popular ones like AppImage, deb, and rpm.

  • AppImage: A universal format that runs on most Linux distributions without installation.
  • deb: For Debian-based systems (Ubuntu, Debian).
  • rpm: For Red Hat-based systems (Fedora, CentOS).

Similar to macOS, you'll often define a category for your application.

Linux Config Example

Here's an example of configuring for Linux, targeting different formats and setting an icon:

{
  "name": "my-electron-app",
  "build": {
    "appId": "com.yourapp.id",
    "linux": {
      "target": [
        "AppImage",
        "deb",
        "rpm"
      ],
      "category": "Development",
      "icon": "build/icon.png"
    }
  }
}

Check Your Packaging Knowledge

Match the `electron-builder` target configuration key with its primary operating system.

Recap & Next Steps

Great job! You've learned the fundamentals of cross-platform packaging with electron-builder.

  • We explored how electron-builder simplifies creating installers for Windows, macOS, and Linux.
  • You saw how to configure platform-specific settings directly in your package.json.
  • Understanding appId and various installer targets (NSIS, DMG, AppImage) is key to successful distribution.

Next, you'll learn about code signing and notarization, essential steps for ensuring your application is trusted by users and operating systems.

Frequently asked questions

Is the “Cross-Platform Packaging” lesson free?

Yes — the full text of “Cross-Platform Packaging” is free to read here on the web, and the Electron Desktop App Development course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Electron Desktop App Development course, upgrade to CoddyKit PRO.

What will I learn in “Cross-Platform Packaging”?

Master advanced packaging options and configurations using `electron-builder` for robust cross-platform distribution. You practise Electron Desktop App Development with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Electron Desktop App Development?

No prior experience is required. Electron Desktop App Development on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Cross-Platform Packaging” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Electron Desktop App Development lesson?

Yes. Every Electron Desktop App Development lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Cross-Platform Packaging
  2. Code Signing and Notarization
  3. Distributing via App Stores
  4. Automating Releases with CI/CD
← Back to Electron Desktop App Development