What is @electron/universal?
@electron/universal is an npm package designed to help developers create and manage universal builds of Electron applications. It allows you to combine multiple platform-specific builds (e.g., macOS, Windows, Linux) into a single package that can be distributed and run on different operating systems.
What are @electron/universal's main functionalities?
Combining Platform-Specific Builds
This feature allows you to combine x64 and arm64 builds of your Electron app into a single universal app. The code sample demonstrates how to use the `makeUniversalApp` function to specify the paths to the x64 and arm64 builds and the output path for the universal app.
const { makeUniversalApp } = require('@electron/universal');
makeUniversalApp({
x64AppPath: 'path/to/x64/app',
arm64AppPath: 'path/to/arm64/app',
outAppPath: 'path/to/universal/app'
}).then(() => {
console.log('Universal app created successfully!');
}).catch((err) => {
console.error('Error creating universal app:', err);
});
Extracting Platform-Specific Builds
This feature allows you to extract the x64 and arm64 builds from a universal app. The code sample demonstrates how to use the `extractFromUniversalApp` function to specify the path to the universal app and the output paths for the extracted x64 and arm64 builds.
const { extractFromUniversalApp } = require('@electron/universal');
extractFromUniversalApp({
universalAppPath: 'path/to/universal/app',
x64AppPath: 'path/to/extracted/x64/app',
arm64AppPath: 'path/to/extracted/arm64/app'
}).then(() => {
console.log('Platform-specific builds extracted successfully!');
}).catch((err) => {
console.error('Error extracting builds:', err);
});
Other packages similar to @electron/universal
electron-builder
electron-builder is a complete solution to package and build a ready-for-distribution Electron app for macOS, Windows, and Linux. It supports creating platform-specific builds and can be configured to handle various build tasks. Unlike @electron/universal, which focuses on creating universal builds, electron-builder provides a broader range of features for packaging and distributing Electron apps.
electron-packager
electron-packager is a command-line tool and Node.js library that bundles Electron-based application source code with a pre-built version of Electron, making it easy to create platform-specific builds. While it does not specifically focus on creating universal builds like @electron/universal, it is a popular tool for packaging Electron apps for different operating systems.
@electron/universal
Create universal macOS Electron applications
Usage
import { makeUniversalApp } from '@electron/universal';
await makeUniversalApp({
x64AppPath: 'path/to/App_x64.app',
arm64AppPath: 'path/to/App_arm64.app',
outAppPath: 'path/to/App_universal.app',
});
FAQ
The app is twice as big now, why?
Well, a Universal app isn't anything magical. It is literally the x64 app and
the arm64 app glued together into a single application. It's twice as big
because it contains two apps in one.
What about native modules?
The way @electron/universal
works today means you don't need to worry about
things like building universal versions of your native modules. As long as
your x64 and arm64 apps work in isolation the Universal app will work as well.
How do I build my app for Apple silicon in the first place?
Check out the Electron Apple silicon blog post