Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
electron-builder
Advanced tools
electron-builder is a complete solution to package and build a ready-for-distribution Electron app with “auto update” support out of the box. It supports numerous target formats and platforms, making it a versatile tool for Electron app developers.
Building for Multiple Platforms
This feature allows you to build your Electron app for multiple platforms such as Windows, macOS, and Linux. The code sample demonstrates how to configure and initiate a build process for a Windows target.
const builder = require('electron-builder');
builder.build({
targets: builder.Platform.WINDOWS.createTarget(),
config: {
appId: 'com.example.app',
productName: 'ExampleApp',
directories: {
output: 'dist'
}
}
}).then(() => {
console.log('Build complete!');
}).catch((error) => {
console.error('Error during build:', error);
});
Auto Update
The auto-update feature allows your app to automatically check for updates and install them. The code sample shows how to set up the auto-updater to check for updates when the app is ready and handle update events.
const { autoUpdater } = require('electron-updater');
app.on('ready', () => {
autoUpdater.checkForUpdatesAndNotify();
});
autoUpdater.on('update-available', () => {
console.log('Update available.');
});
autoUpdater.on('update-downloaded', () => {
autoUpdater.quitAndInstall();
});
Custom Configuration
This feature allows you to customize the build configuration for your Electron app. The code sample demonstrates how to specify custom directories, files, and target formats for different platforms.
const builder = require('electron-builder');
builder.build({
config: {
appId: 'com.example.app',
productName: 'ExampleApp',
directories: {
output: 'dist'
},
files: [
'build/**/*'
],
extraResources: [
'assets/'
],
win: {
target: 'nsis'
},
mac: {
target: 'dmg'
}
}
}).then(() => {
console.log('Build complete!');
}).catch((error) => {
console.error('Error during build:', error);
});
electron-packager is a command-line tool and Node.js library that bundles Electron-based application source code with a renamed Electron executable and supporting files into folders ready for distribution. Unlike electron-builder, it does not include auto-update support out of the box and is generally considered less feature-rich.
electron-forge is a complete tool for creating, publishing, and installing modern Electron applications. It provides a more integrated development experience compared to electron-builder, including project scaffolding, packaging, and publishing. However, it may not offer the same level of customization and flexibility in build configurations.
electron-updater is a standalone module that provides auto-update functionality for Electron apps. While electron-builder includes auto-update support as part of its feature set, electron-updater can be used independently or in conjunction with other packaging tools like electron-packager.
The electron-builder project is used to create installers for the platforms Windows and OS X. It's built to work together with the electron-packager.
If you are looking for a complete set up on how to use the electron-packager and electron-builder check the "How we use it section below".
The project has currently only been executed on OS X machines. Any support or help for Windows is welcome.
You can go the global installation route. ;)
$ npm install -g electron-builder
Oooooor... You can wrap electron-builder
with npm scripts
to not have a global dependency.
# install electron builder as a dependency of your project
$ npm install --save electron-builder
After that you can easily use the electron-builder
binary in your npm scripts
.
part of package.json
{
"scripts" : {
"pack:osx": "npm run build:osx && electron-builder \"dist/osx/Loopline Systems.app\" --platform=osx --out=\"dist/osx\" --config=packager.json"
}
}
If you're on OS X/Linux and want to build for Windows, you need Wine installed. Wine is required in order to set the correct icon for the exe.
You will also need the nullsoft scriptable install system for all platforms.
On OS X via brew
$ brew install wine makensis
On linux via apt-get
$ add-apt-repository ppa:ubuntu-wine/ppa -y
$ apt-get update
$ apt-get install wine nsis -y
On Windows download the nullsoft scriptable installer
If you're on OS X/Linux and want to build for Windows, make also sure you're running at least v0.12.0
of node.js.
$ node --version
v0.12.0
$ electron-builder dist/osx/someFancy.app --platform=osx --out=/some/path/ --config=config.json
$ electron-builder dist/win/someFancy-win32 --platform=win --out=/some/path/ --config=config.json
Usage
$ electron-builder <sourcedir> --platform=<platform> --config=<configPath> --out=<outputPath>
Required options:
platform: win, osx
config: path to config file
Optional options:
out: path to output the installer (must exist)
Because the configuration is fairly complex we decided to go with a good old config file for now. You will find a sample config file below.
config.json.sample:
{
"osx" : {
"title": "Loopline Systems",
"background": "assets/osx/installer.png",
"icon": "assets/osx/mount.icns",
"icon-size": 80,
"contents": [
{ "x": 438, "y": 344, "type": "link", "path": "/Applications" },
{ "x": 192, "y": 344, "type": "file" }
]
},
"win" : {
"title" : "Loopline Systems",
"icon" : "assets/win/icon.ico"
}
}
When you run npm run pack
it will create executables for the platforms Windows and OS X inside of the dist
directory. It grabs the generated executables afterwards to create the installers out of it.
directory structure
desktop
|-- app // actual electron application
|
|-- assets // build related assets
|-- osx // build assets for OS X
|-- installer.png // -> referenced in packager.json ( dmg mount icon )
|-- mount.icns // -> use by electron-packager ( actual app icon )
|-- loopline.icns // -> referenced in packager.json ( dmg background )
|-- win // build assets for OS X
|-- icon.ico // -> referenced in packager.json
|
|-- dist // out put folder
|-- osx // generated executables for OS X
|-- Loopline Systems.app
|-- Loopline Systems.dmg
|-- win // generated executables for Windows
|-- Loopline Systems-win32
|-- Loopline Systems Setup.exe
|-- package.json
|-- packager.json
package.json
{
"name": "loopline-desktop",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "electron ./app",
"clean": "rm -rf ./dist",
"clean:osx": "rm -rf ./dist/osx",
"clean:win": "rm -rf ./dist/win",
"build": "npm run clean && npm run build:osx && npm run build:win",
"build:osx": "npm run clean:osx && electron-packager ./app \"Loopline Systems\" --out=dist/osx --platform=darwin --arch=x64 --version=0.25.3 --icon=assets/osx/loopline.icns",
"build:win": "npm run clean:win && electron-packager ./app \"Loopline Systems\" --out=dist/win --platform=win32 --arch=ia32 --version=0.25.3 --icon=assets/win/icon.ico",
"pack": "npm run pack:osx && npm run pack:win",
"pack:osx": "npm run build:osx && electron-builder \"dist/osx/Loopline Systems.app\" --platform=osx --out=\"dist/osx\" --config=packager.json",
"pack:win": "npm run build:win && electron-builder \"dist/win/Loopline Systems-win32\" --platform=win --out=\"dist/win\" --config=packager.json"
},
"dependencies": {
"electron-packager": "^4.0.2",
"electron-prebuilt": "^0.25.2",
"electron-builder": "^1.0.0"
}
}
packager.json
{
"osx" : {
"title": "Loopline Systems",
"background": "assets/osx/installer.png",
"icon": "assets/osx/mount.icns",
"icon-size": 80,
"contents": [
{ "x": 438, "y": 344, "type": "link", "path": "/Applications" },
{ "x": 192, "y": 344, "type": "file" }
]
},
"win" : {
"title" : "Loopline Systems",
"icon" : "assets/win/icon.ico"
}
}
You want to help out and have ideas to make it better? Great!
Create an issue and we will tackle it.
If you decide to propose a pull request ( even better ) make sure npm test
is succeeding.
For releases we like to give release names via adj-noun. You'll find proper release notes here.
FAQs
A complete solution to package and build a ready for distribution Electron app for MacOS, Windows and Linux with “auto update” support out of the box
The npm package electron-builder receives a total of 116,400 weekly downloads. As such, electron-builder popularity was classified as popular.
We found that electron-builder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.