官术网_书友最值得收藏!

Packaging for macOS

If you intend to publish our application to the App Store, you should provide an application ID and category settings. Open the project's package.json file for editing, and append the following section to the end of the file:

{
"build": {
"appId": "com.my.app.id",
"mac": {
"category": "public.app-category.utilities"
}
}
}

Feel free to customize the values and provide the relevant information later. For now, you can leave those values as they are.

There are two ways you can build your application: through the development and production modes. Let's start with the development script, which allows you to quickly run and see that your application is working as expected:

  1. Update the package.json file and add the build:macos entry to the scripts section, as shown in the following code:
      {
"scripts": {
"start": "electron .",
"build:macos": "electron-builder --macos --dir"
}
}

Just like the npm start command we used earlier, you can customize all the parameters in a single place. You only need to remember and document a simple command npm run build:macos.

  1. To build the application for development, open the Terminal window in VS Code and run the build:macos script, as follows:
      npm run build:macos
  1. After a few seconds, you will see the build's output in the dist/mac folder:
  1. Double-click on the icon to run your simple Electron application locally.
  2. Let's also add the necessary script so that we can create production or distribution packages. Append the dist:macos entry to the scripts section, as shown in the following code:
      {
"scripts": {
"start": "electron .",
"build:macos": "electron-builder --macos --dir",
"dist:macos": "electron-builder --macos"
}
}

Now, you have two scripts that handle running and packaging on your macOS machine.

Running the dist:macos script takes a bit longer than the build:macos one. After running the script, you get several different packages in the dist folder of your project: my-first-app-1.0.0.dmg, a typical macOS installer; my-first-app-1.0.0-mac.zip, an archived installer so that you can distribute it easily; and, of course, mac/my-first-app, which includes the ready-to-launch application:

Try running the .dmg file; you should see the typical macOS installer:

Please refer to the electron-builder documentation for ideas and tips on how to customize it: https://www.electron.build/configuration/dmg.

Congratulationsyou've got your first cross-platform Electron application installer up and running on macOS!

主站蜘蛛池模板: 呼和浩特市| 阜南县| 江陵县| 肥城市| 甘谷县| 玉溪市| 成武县| 灌阳县| 巴楚县| 长泰县| 玉树县| 承德市| 洞口县| 平顶山市| 迭部县| 尉犁县| 江都市| 新密市| 龙门县| 鄂托克旗| 同仁县| 乌鲁木齐县| 融水| 滕州市| 福贡县| 夏河县| 长沙市| 保靖县| 无棣县| 团风县| 山西省| 绍兴市| 山西省| 吐鲁番市| 镶黄旗| 香河县| 滨海县| 新竹县| 鄂托克前旗| 南京市| 阜平县|