Application Packaging应用程序打包
To distribute your app with Electron, you need to package and rebrand it. 要使用Electron分发应用程序,您需要对其进行打包并重新品牌。To do this, you can either use specialized tooling or manual approaches.为此,您可以使用专用工具或手动方法。
With tooling带工具
There are a couple tools out there that exist to package and distribute your Electron app. 有几个工具可以打包和分发您的Electron应用程序。We recommend using Electron Forge. 我们建议使用Electron锻造。You can check out its documentation directly, or refer to the Packaging and Distribution part of the Electron tutorial.您可以直接查看其文档,或者参考Electron教程的打包和分发部分。
Manual packaging手工包装
If you prefer the manual approach, there are 2 ways to distribute your application:如果您更喜欢手动方法,有两种方法可以分发应用程序:
With prebuilt binaries使用预构建的二进制文件With an app source code archive使用应用程序源代码存档
With prebuilt binaries使用预构建的二进制文件
To distribute your app manually, you need to download Electron's prebuilt binaries. 要手动分发应用程序,您需要下载Electron的预构建二进制文件。Next, the folder containing your app should be named 接下来,包含应用程序的文件夹应命名为app
and placed in Electron's resources directory as shown in the following examples.app
,并放置在Electron的资源目录中,如以下示例所示。
The location of Electron's prebuilt binaries is indicated with 在下面的示例中,Electron的预构建二进制文件的位置用electron/
in the examples below.electron/
表示。
electron/Electron.app/Contents/Resources/app/
├── package.json
├── main.js
└── index.html
electron/resources/app
├── package.json
├── main.js
└── index.html
Then execute 然后在macOS上执行Electron.app
on macOS, electron
on Linux, or electron.exe
on Windows, and Electron will start as your app. Electron.app
,在Linux上执行electron
,或在Windows上执行electron.exe
,Electron将作为您的应用程序启动。The electron
directory will then be your distribution to deliver to users.electron
目录将是您的分发版,以交付给用户。
With an app source code archive (asar)使用应用程序源代码存档(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.如果您尚未使用Parcel或Webpack等捆绑包,您可以将应用程序打包到asar存档中,以提高在Windows等平台上读取文件的性能,而不是通过复制其所有源文件来发送应用程序。
To use an 要使用asar
archive to replace the app
folder, you need to rename the archive to app.asar
, and put it under Electron's resources directory like below, and Electron will then try to read the archive and start from it.asar
存档替换应用程序文件夹,您需要将存档重命名为app.asar
,并将其放在Electron的资源目录下,如下所示,然后Electron将尝试读取存档并从中开始。
electron/Electron.app/Contents/Resources/
└── app.asar
electron/resources/
└── app.asar
You can find more details on how to use 您可以在asar
in the electron/asar
repository.electron/asar
存储库中找到有关如何使用asar
的更多详细信息。
Rebranding with downloaded binaries使用下载的二进制文件重塑品牌
After bundling your app into Electron, you will want to rebrand Electron before distributing it to users.将应用程序捆绑到Electron中后,在将其分发给用户之前,您将需要重新命名Electron。
-
Windows:
You can rename您可以将electron.exe
to any name you like, and edit its icon and other information with tools like rcedit.electron.exe
重命名为任何您喜欢的名称,并使用rcedit等工具编辑其图标和其他信息。 -
Linux:
You can rename the您可以将electron
executable to any name you like.electron
可执行文件重命名为您喜欢的任何名称。 -
macOS:
You can rename您可以将Electron.app
to any name you want, and you also have to rename theCFBundleDisplayName
,CFBundleIdentifier
andCFBundleName
fields in the following files:Electron.app
重命名为您想要的任何名称,还必须重命名以下文件中的CFBundleDisplayName
、CFBundleIdentifier
和CFBundleName
字段:Electron.app/Contents/Info.plist
Electron.app/Contents/Frameworks/Electron Helper.app/Contents/Info.plist
You can also rename the helper app to avoid showing您还可以重命名助手应用程序,以避免在活动监视器中显示Electron Helper
in the Activity Monitor, but make sure you have renamed the helper app's executable file's name.Electron Helper
,但请确保已重命名助手应用的可执行文件名。The structure of a renamed app would be like:重命名应用程序的结构如下:
MyApp.app/Contents
├── Info.plist
├── MacOS/
│ └── MyApp
└── Frameworks/
└── MyApp Helper.app
├── Info.plist
└── MacOS/
└── MyApp Helper
it is also possible to rebrand Electron by changing the product name and building it from source. 也可以通过更改产品名称并从源代码构建来重新命名Electron。To do this you need to set the build argument corresponding to the product name (为此,您需要在electron_product_name = "YourProductName"
) in the args.gn
file and rebuild.args.gn
文件中设置与产品名称(electron_product_name = "YourProductName"
)对应的构建参数,然后重新构建。
Keep in mind this is not recommended as setting up the environment to compile from source is not trivial and takes significant time.请记住,不建议这样做,因为设置从源代码编译的环境并不简单,而且需要花费大量时间。