The short answer
Short answer: a universal package is not compiled in one go. You build the x64 and arm64 apps separately, then merge them with @electron/universal. The result has to be signed again after merging, so do it on a Mac. The cost is a size close to the two apps combined, and whether that is worth it depends on which chips your users have.
Which steps require macOS
Why do it on macOS
@electron/universalglues an x64 app and an arm64 app together into a universal macOS binary. After merging it has to be signed again, and macOS signing can only be done on macOS.- For projects with native modules, you need compiled output for both architectures, which is most straightforward on a Mac.
What you can prepare on other operating systems
- Write the merge options into the config (see step 3) and commit them.
- Take stock of the native modules among your dependencies and confirm each one supports both architectures.
Do you need a universal package at all
The alternative is to ship separate x64 and arm64 installers and let users choose. A universal package removes the choice in exchange for roughly twice the size. The FAQ for @electron/universal explains the size bluntly: there are two apps inside. When the app itself is large or carries a lot of resource files, offering them separately may suit better.
How to do it on a remote Mac
Confirm each architecture runs on its own
The
@electron/universalreadme states a precondition: as long as the x64 and arm64 apps each run correctly in isolation, the merged universal app will run correctly as well. So first build each architecture separately on the remote Mac and launch it to verify. Running the x64 version on an Apple silicon Mac needs Rosetta. Check for yourself whether it is already installed on the machine.Produce the universal package with the packaging tool's flag
- Electron Forge: the make command's
--archflag acceptsuniversal, for examplenpm run make -- --arch=universal. - electron-builder:
npx electron-builder --mac --universal.
Both call
@electron/universalunderneath and carry out the "build twice, then merge" process automatically, so it takes clearly longer than a single-architecture build.- Electron Forge: the make command's
Understand the three merge options
electron-builder puts them under
mac.universal. When calling the library yourself they are parameters of the same names:mergeASARs: merges the ASAR archives of the two architectures into one universal ASAR. On by default in electron-builder.singleArchFiles: a matching pattern declaring which files only appear in the ASAR of one architecture. Without the declaration, the tool raises an error when it finds a file present for only one architecture.x64ArchFiles: a matching pattern declaring single-architecture Mach-O files that are identical in both builds, so the tool does not try to merge them again.
When the app carries binary resources that were already merged with
lipo, this last option is also how you tell the tool not to process them a second time.Deal with native modules
The library's readme says that by default you do not need to compile universal versions of native modules yourself, and the tool handles the output of each architecture. In practice, trouble mostly comes from a dependency that only provides a prebuilt file for one architecture. The order of fixes: first see whether the module supports compiling the other architecture from source. If it does not, declare it with
singleArchFilesand confirm it is not loaded at runtime on the other architecture.Call the library yourself when you need to control the process
makeUniversalApptakes three paths:x64AppPath,arm64AppPathandoutAppPath. The readme specifically notes these parameters must be absolute paths. This suits projects with an unusual build process that want to cache the output of the two architectures step by step.Sign, notarize and verify after merging
The universal app is signed and notarized as a single unit, the same way as a single-architecture app. See Electron signing and notarization. Finally, install and run it on the remote Mac. If circumstances allow, ask a user with an Intel Mac to try installing it once as well.
FAQ
Merging reports that a file exists for only one architecture
This is the tool's safeguard: it found an architecture-specific file that you have not declared. After confirming the file really is only needed for one architecture, add a pattern matching it to singleArchFiles.
What should I watch for with auto-update on a universal package?
The update package is universal too, so its size doubles along with it. When releasing per architecture, the update service has to serve different download URLs per architecture. A universal package needs no such split, but each update is a bigger download. Weigh it against your users' network conditions.
Does the Mac App Store version need to be universal?
This is a distribution strategy question, not a tool limitation. The store shows only one app, and making it universal lets users on both kinds of chips install it. The submission flow is in Electron store submission and distribution.
Does building twice put demands on the machine's specs?
A universal build is roughly equivalent to doing two full packaging runs back to back, so both time and disk usage are higher. We have no measured data and give no specific figures. For available configurations, see the plans page. For renting versus buying for long-term use, see rent vs buy a Mac mini.
Related
- Can I build a macOS installer for an Electron app on Windows or Linux?
- How do I sign and notarize an Electron app for macOS without a Mac?
- How do I publish an Electron app to the Mac App Store or distribute a dmg without a Mac?
- Should I rent a Mac mini or buy one?
Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support