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

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!

主站蜘蛛池模板: 房山区| 新宾| 桃江县| 定兴县| 都江堰市| 江达县| 天全县| 汉中市| 英超| 黄浦区| 岳阳市| 台中县| 将乐县| 玉门市| 元江| 肇东市| 南陵县| 榆林市| 六枝特区| 卓资县| 昭苏县| 凉山| 镇巴县| 漠河县| 神农架林区| 克什克腾旗| 福贡县| 平度市| 鄂托克前旗| 远安县| 都安| 左贡县| 巴楚县| 金平| 邻水| 富民县| 江门市| 克什克腾旗| 中山市| 吴忠市| 龙游县|