Перейти к основному содержанию

Упаковка приложений

To distribute your app with Electron, you need to package and rebrand it. To do this, you can either use specialized tooling or manual approaches.

С инструментами

There are a couple tools out there that exist to package and distribute your Electron app. We recommend using Electron Forge. You can check out its documentation directly, or refer to the Packaging and Distribution part of the Electron tutorial.

Manual packaging

If you prefer the manual approach, there are 2 ways to distribute your application:

  • С предустановленными бинарными файлами
  • С архивом исходного кода приложения

С предустановленными бинарными файлами

Для ручного распространения вашего приложения Electron, вам нужно скачать предварительно собранные двоичные файлы Electron. Далее папку, содержащую ваше приложение следует назвать app и поместить в каталог ресурсов Electron, как показано в следующих примерах.

примечание

The location of Electron's prebuilt binaries is indicated with electron/ in the examples below.

macOS
electron/Electron.app/Contents/Resources/app/
├── package.json
├── main.js
└── index.html
Windows and Linux
electron/resources/app
├── package.json
├── main.js
└── index.html

Then execute Electron.app on macOS, electron on Linux, or electron.exe on Windows, and Electron will start as your app. The electron directory will then be your distribution to deliver to users.

With an app source code archive (asar)

Instead of shipping your app by copying all of its source files, you can package your app into an asar archive to improve the performance of reading files on platforms like Windows, if you are not already using a bundler such as Parcel or Webpack.

Чтобы использовать архив asar для замены каталога app, необходимо переименовать архив в app.asar и положить его в каталог ресурсов Electron, как показано ниже, и Electron будет пытаться прочитать архив и начать с него.

macOS
electron/Electron.app/Contents/Resources/
└── app.asar
Windows
electron/resources/
└── app.asar

Более подробную информацию об использовании asar вы можете найти в репозитории electron/asar.

Ребрендинг скачанных бинарных файлов

После построения вашего приложения в Electron и перед распространением вам следует провести его ребрендинг.

  • Windows: You can rename electron.exe to any name you like, and edit its icon and other information with tools like rcedit.

  • Linux: You can rename the electron executable to any name you like.

  • macOS: You can rename Electron.app to any name you want, and you also have to rename the CFBundleDisplayName, CFBundleIdentifier and CFBundleName fields in the following files:

    • Electron.app/Contents/Info.plist
    • Electron.app/Contents/Frameworks/Electron Helper.app/Contents/Info.plist

    Вы также можете переименовать helper приложения, чтобы избежать показа Electron Helper в Activity Monitor, но убедитесь, что вы переименовали имя исполняемого файла helper приложения.

    Структура переименования app будет такая:

MyApp.app/Contents
├── Info.plist
├── MacOS/
│ └── MyApp
└── Frameworks/
└── MyApp Helper.app
├── Info.plist
└── MacOS/
└── MyApp Helper
примечание

можно изменить бренд Electron путем изменения имени продукта и сборки его из исходных кодов. Для этого вам надо установить аргумент, отвечающий за имя продукта (electron_product_name = "YourProductName") в файле args.gn и пересобрать Electron.

Keep in mind this is not recommended as setting up the environment to compile from source is not trivial and takes significant time.