The electron-builder provides us with a way to distribute a pre-release version. Three release channels are available: "latest", "beta" and "alpha." The default is "latest". The release channels of both "beta" and "alpha" are usable as pre-release versions.
Add "-beta" or "-alpha" to the version name #
It's simple to use it. If we want to build a beta version app, we add "-beta" to the version name in package.json.
"name": "my-electron-app",
"version": "1.2.3-beta",
After this change in package.json, the electron-builder outputs beta.yml instead of latest.yml when building. Of course, the file name of the built application is also changed to 1.2.3-beta. The difference between beta.yml and latest.yml is the version name of the "version" property and the file name of the "file.urls" property. An example of beta.yml is below.
version: 1.2.3-beta
files:
- url: my-electron-app Setup 1.2.3-beta.exe
If we want to support all three release channels, we should add build.generateUpdatesFilesForAllChannels: true to package.json or a config file for electron-builder.
"build": {
"generateUpdatesFilesForAllChannels": true,
...
}
The yml files the electron-builder builds depend on the version name and the boolean value of generateUpdateFilesForAllChannels. The table below shows the built files. The setting of generateUpdatesFilesForAllChannels affects what yml files the electron-builder outputs.
| version | generateUpdateFilesForAllChannels | yml file | app file |
|---|---|---|---|
| 1.2.3 | false (default) | latest.yml | my-electron-app Setup 1.2.3.exe |
| 1.2.3 | true | alpha.yml, beta.yml, latest.yml | my-electron-app Setup 1.2.3.exe |
| 1.2.3-beta | false (default) | beta.yml | my-electron-app Setup 1.2.3-beta.exe |
| 1.2.3-beta | true | alpha.yml, beta.yml | my-electron-app Setup 1.2.3-beta.exe |
| 1.2.3-alpha | false (default) | alpha.yml | my-electron-app Setup 1.2.3-alpha.exe |
| 1.2.3-alpha | true | alpha.yml | my-electron-app Setup 1.2.3-alpha.exe |
The app file and the blockmap file depend on only the version name. For example, If the version name in package.json is "1.2.3-beta", the electron-builder outputs my-electron-app Setup 1.2.3-beta.exe. Even if generateUpdatesFilesForAllChannel is set to true, the electron-builder doesn't build either the stable version (my-electron-app Setup 1.2.3.exe) or another pre-release version (my-electron-app Setup 1.2.3-alpha.exe).
Don't forget the setting for AutoUpdate #
To support AutoUpdate for pre-release versions, autoUpdater.channel should be set in the main process of an Electron app.
import { autoUpdater } from 'electron-updater';
app.on('ready', () => {
autoUpdater.channel = "beta";
autoUpdater.checkForUpdatesAndNotify();
});
The value of autoUpdater.channel allows users to get the pre-release versions.
| autoUpdater.channel | available versions |
|---|---|
| latest(default) | latest |
| beta | beta, latest |
| alpha | alpha, beta, latest |
If autoUpdater.channel is set to "beta", users can get the released beta version or the latest version.
Wrap up #
- Add "-beta" or "-alpha" to the version name in
package.json - (Option) Add
build.generateUpdatesFilesForAllChannels: truetopackage.jsonor a config file for electron-builder - Add the setting of
autoUpdater.channelto the main process of an Electron app