Create Universal macOS applications from two x64 and arm64 Electron applications
Перейти к файлу
dependabot[bot] 7f59407631
build(deps): bump cross-spawn from 7.0.3 to 7.0.6 (#114)
Bumps [cross-spawn](https://github.com/moxystudio/node-cross-spawn) from 7.0.3 to 7.0.6.
- [Changelog](https://github.com/moxystudio/node-cross-spawn/blob/master/CHANGELOG.md)
- [Commits](https://github.com/moxystudio/node-cross-spawn/compare/v7.0.3...v7.0.6)

---
updated-dependencies:
- dependency-name: cross-spawn
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-11-18 18:31:12 -05:00
.circleci chore: bump electronjs/node in .circleci/config.yml to 2.3.1 (#111) 2024-10-26 10:08:58 -04:00
.github build(deps): bump dsanders11/project-actions from 1.3.0 to 1.4.0 (#112) 2024-11-08 21:22:48 -08:00
.husky build: update dependencies to clean up 'yarn audit' 2022-11-26 19:08:03 -08:00
entry-asar fix: use Typescript for files in `entry-asar` (#83) 2023-11-02 19:10:17 -03:00
src docs: additional API docs (#100) 2024-06-21 14:21:47 -07:00
test test: improve coverage (#102) 2024-06-17 15:15:20 -07:00
.gitignore docs: additional API docs (#100) 2024-06-21 14:21:47 -07:00
.prettierrc.json docs: additional API docs (#100) 2024-06-21 14:21:47 -07:00
.releaserc.json build: configure semantic release for main branch 2022-10-18 16:08:05 -07:00
LICENSE chore: add LICENSE file to match package.json (#63) 2023-01-31 11:14:06 -08:00
README.md docs: additional API docs (#100) 2024-06-21 14:21:47 -07:00
jest.config.js feat: bump minimum node version to 16 and add tests (#86) 2023-11-09 11:08:39 -08:00
jest.setup.ts test: improve coverage (#102) 2024-06-17 15:15:20 -07:00
package.json build: bump lint-staged to clear audit (#109) 2024-10-02 10:29:07 -07:00
tsconfig.cjs.json fix: use Typescript for files in `entry-asar` (#83) 2023-11-02 19:10:17 -03:00
tsconfig.entry-asar.json fix: use Typescript for files in `entry-asar` (#83) 2023-11-02 19:10:17 -03:00
tsconfig.esm.json fix: use Typescript for files in `entry-asar` (#83) 2023-11-02 19:10:17 -03:00
tsconfig.jest.json feat: bump minimum node version to 16 and add tests (#86) 2023-11-09 11:08:39 -08:00
tsconfig.json fix: import for path now compiles correctly after TypeScript was added (#85) 2023-11-05 11:37:48 -03:00
typedoc.json docs: additional API docs (#100) 2024-06-21 14:21:47 -07:00
yarn.lock build(deps): bump cross-spawn from 7.0.3 to 7.0.6 (#114) 2024-11-18 18:31:12 -05:00

README.md

@electron/universal

Create universal macOS Electron applications

CircleCI NPM package

Usage

This package takes an x64 app and an arm64 app and glues them together into a Universal macOS binary.

Note that parameters need to be absolute paths.

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',
});

Advanced configuration

The basic usage patterns will work for most apps out of the box. Additional configuration options are available for advanced usecases.

Merging ASAR archives to reduce app size

Added in v1.2.0

If you are using ASAR archives to store your Electron app's JavaScript code, you can use the mergeASARs option to merge your x64 and arm64 ASAR files to reduce the bundle size of the output Universal app.

If some files are present in only the x64 app but not the arm64 version (or vice-versa), you can exclude them from the merging process by specifying a minimatch pattern in singleArchFiles.

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',
  mergeASARs: true,
  singleArchFiles: 'node_modules/some-native-module/lib/binding/Release/**', // if you have files in your asar that are unique to x64 or arm64 apps
});

If @electron/universal detects an architecture-unique file that isn't covered by the singleArchFiles rule, an error will be thrown.

Skip lipo for certain binaries in your Universal app

Added in 1.3.0

If your Electron app contains binary resources that are already merged with the lipo tool, providing a minimatch pattern to matching files in the x64ArchFiles parameter will prevent @electron/universal from attempting to merge them a second time.

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',
  mergeASARs: true,
  x64ArchFiles: '*/electron-helper', // `electron-helper` is a binary merged using `lipo`
});

If @electron/universal detects a lipo'd file that isn't covered by the x64ArchFiles rule, an error will be thrown.

Including already codesigned app bundles into your Universal app

Added in v1.4.0

By default, the merging process will generate an ElectronAsarIntegrity key for any Info.plist files in your Electron app.

If your Electron app bundles another .app that is already signed, you need to use the infoPlistsToIgnore option to avoid modifying that app's plist.

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',
  infoPlistsToIgnore: 'my-internal.app/Contents/Info.plist'
});

FAQ

The app is twice as big now, why?

A Universal app is just 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.

Merging your ASAR bundles can yield significant app size reductions depending on how large your app.asar file is.

What about native modules?

Out of the box, you don't need to worry about 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.

Note that if you are using mergeASARs, you may need to add architecture-specific binary resources to the singleArchFiles pattern. See Merging ASARs usage for an example.

How do I build my app for Apple silicon in the first place?

Check out the Electron Apple silicon blog post.