Congratulations on building your Electron application! The next crucial step is to make it accessible to your users. This involves packaging your application into an installer that's native to their operating system. Fortunately, Electron provides excellent tools to streamline this process for Windows, macOS, and Linux.
We'll primarily use a popular and powerful tool called electron-builder to handle the complexities of creating installers for various platforms. This tool supports a wide range of installer formats, including NSIS and Squirrel for Windows, DMG and Mac App Store for macOS, and AppImage, deb, and rpm for Linux.
Before we dive into the commands, make sure you have electron-builder installed as a development dependency in your project.
npm install --save-dev electron-builderNext, you'll want to configure electron-builder in your package.json file. This configuration tells electron-builder how to build your application, including information about your app, target platforms, and specific builder options.
"build": {
"appId": "com.your-company.your-app-name",
"productName": "Your App Name",
"directories": {
"output": "dist/"
},
"win": {
"target": "nsis"
},
"mac": {
"target": "dmg"
},
"linux": {
"target": "appImage"
}
}In this build object, you'll find several important properties:
appId: A unique identifier for your application. It's crucial for updates and licensing.productName: The human-readable name of your application.directories.output: Specifies the directory where the build artifacts will be placed.win,mac,linux: These objects define platform-specific build configurations. Here, we've set the default target for each platform. You can specify multiple targets or customize them further.
Now, let's add scripts to your package.json to make building easy.