Electron Projects
上QQ阅读APP看书,第一时间看更新

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!