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

Packaging for Windows

Now that you know how to set up build scripts for macOS and Ubuntu Linux, configuring for Windows shouldn't be a problem for you.

As I mentioned earlier, it is possible and also recommended to keep the configuration files for all platforms in a single code repository, inside the package.json file. The build scripts for Windows are shown in the following code:

{
"scripts": {
"start": "electron .",
"build:windows": "electron-builder --win --dir",
"dist:windows": "electron-builder --win"
}
}

Both scripts should be familiar to you. The build:windows script creates an unpacked local build for development and testing purposes, while the dist:windows script prepares the application for distribution.

Let's try to build and run the development version of the application:

  1. Open the Terminal window in Visual Studio Code, or a Command Prompt tool, and run the following script:
      npm run build:windows
Note that you can build Windows packages with macOS or Ubuntu Linux if you have the Wine tool installed, but I recommend having a virtual machine nearby for testing purposes. It should also be possible to build for Linux on a Windows machine, but you may want to have a real Linux machine for application testing purposes.
  1. Once the script exits, you should see the prebuilt application, that is, my-first-app.exe, in the dist/win-unpacked folder.
  2. Double-click on the my-first-app.exe file to run the application:
  1. We need to use the build:windows script to create a distribution package for testing purposes. Let's check that we can build packages for redistribution:
      npm run dist:windows
  1. Check the dist folder once again. You should see the my-first-app Setup 1.0.0.exe installer file alongside the win-unpacked folder:

  1. Now, double-click the installer file. The setup wizard should set up the application and automatically launch it.

Congratulationsyou've got your first cross-platform Electron application package up and running on Windows 10!

主站蜘蛛池模板: 渭源县| 元朗区| 普陀区| 扎赉特旗| 东方市| 冕宁县| 佛学| 通州市| 芜湖市| 甘洛县| 顺平县| 怀柔区| 楚雄市| 南澳县| 永顺县| 大埔县| 高密市| 石泉县| 枣强县| 贞丰县| 乡城县| 阿荣旗| 昭苏县| 津南区| 麻阳| 文昌市| 高雄县| 常熟市| 仙游县| 怀集县| 玉环县| 常宁市| 云阳县| 华安县| 若羌县| 景德镇市| 合肥市| 中方县| 兴仁县| 九龙坡区| 湟源县|