• Stars
    star
    470
  • Rank 93,399 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create a Windows package for your Electron app.

Electron Installer for Windows

electron-installer-windows Version Linux/macOS Build Status Windows Build Status

Create a Windows package for your Electron app.

This tool relies on the awesome Squirrel.Windows framework written by @anaisbetts. It takes care of creating the actual package, signing it, dealing with updates, and many more things. Gotta give credit where credit is due, ya know.

Requirements

This tool requires Node 12 or greater.

I'd recommend building your packages on your target platform, but if you have to run this on Mac OS X or Linux, you will need to install mono and wine through your package manager.

You won't get an .msi installer though, only .nupkg and .exe installers. To get an .msi installer you'll need to run on Windows.

Installation

For use from command-line:

$ npm install -g electron-installer-windows

For use in npm scripts or programmatically:

$ npm install --save-dev electron-installer-windows

Usage

Say your Electron app lives in path/to/app and has a structure like this:

.
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ node_modules
โ”‚ย ย  โ”œโ”€โ”€ electron-packager
โ”‚ย ย  โ””โ”€โ”€ electron-prebuilt
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ resources
โ”‚ย ย  โ”œโ”€โ”€ Icon.png
โ”‚ย ย  โ”œโ”€โ”€ IconTemplate.png
โ”‚ย ย  โ””โ”€โ”€ [email protected]
โ””โ”€โ”€ src
    โ”œโ”€โ”€ index.js
    โ”œโ”€โ”€ main
    โ”‚ย ย  โ””โ”€โ”€ index.js
    โ””โ”€โ”€ renderer
        โ”œโ”€โ”€ index.html
        โ””โ”€โ”€ index.js

You now run electron-packager to build the app for Windows:

$ electron-packager . app --platform win32 --arch x64 --out dist/

And you end up with something like this in your dist folder:

.
โ””โ”€โ”€ dist
 ย ย  โ””โ”€โ”€ app-win32-x64
        โ”œโ”€โ”€ LICENSE
        โ”œโ”€โ”€ LICENSES.chromium.html
        โ”œโ”€โ”€ content_resources_200_percent.pak
        โ”œโ”€โ”€ content_shell.pak
        โ”œโ”€โ”€ d3dcompiler_47.dll
        โ”œโ”€โ”€ icudtl.dat
        โ”œโ”€โ”€ libEGL.dll
        โ”œโ”€โ”€ libGLESv2.dll
        โ”œโ”€โ”€ locales
        โ”œโ”€โ”€ msvcp120.dll
        โ”œโ”€โ”€ msvcr120.dll
        โ”œโ”€โ”€ natives_blob.bin
        โ”œโ”€โ”€ node.dll
        โ”œโ”€โ”€ pdf.dll
        โ”œโ”€โ”€ app.exe
        โ”œโ”€โ”€ resources
        โ”œโ”€โ”€ snapshot_blob.bin
        โ”œโ”€โ”€ ui_resources_200_percent.pak
        โ”œโ”€โ”€ vccorlib120.dll
        โ”œโ”€โ”€ version
        โ””โ”€โ”€ xinput1_3.dll

How do you turn that into a Windows package that your users can install?

Command-Line

If you want to run electron-installer-windows straight from the command-line, install the package globally:

$ npm install -g electron-installer-windows

And point it to your built app:

$ electron-installer-windows --src dist/app-win32-x64/ --dest dist/installers/

You'll end up with the package at dist/installers/app-0.0.1-setup.exe.

Scripts

If you want to run electron-installer-windows through npm, install the package locally:

$ npm install --save-dev electron-installer-windows

Edit the scripts section of your package.json:

{
  "name": "app",
  "description": "An awesome app!",
  "version": "0.0.1",
  "scripts": {
    "start": "electron .",
    "build": "electron-packager . app --platform win32 --arch x64 --out dist/",
    "setup": "electron-installer-windows --src dist/app-win32-x64/ --dest dist/installers/"
  },
  "devDependencies": {
    "electron-installer-windows": "*",
    "electron-packager": "*",
    "electron-prebuilt": "*"
  }
}

And run the script:

$ npm run setup

You'll end up with the package at dist/installers/app-0.0.1-setup.exe.

Programmatically

Install the package locally:

$ npm install --save-dev electron-installer-windows

And write something like this:

const installer = require('electron-installer-windows')

const options = {
  src: 'dist/app-win32-x64/',
  dest: 'dist/installers/'
}

async function main (options) {
  console.log('Creating package (this may take a while)')
  try {
    await installer(options)
    console.log(`Successfully created package at ${options.dest}`)
  } catch (err) {
    console.error(err, err.stack)
    process.exit(1)
  }
}
main(options)

You'll end up with the package at dist/installers/app-0.0.1-setup.exe.

Note: As of 2.0.0, the Node-style callback pattern is no longer available. You can use util.callbackify if this is required for your use case.

Options

Even though you can pass most of these options through the command-line interface, it may be easier to create a configuration file:

{
  "dest": "dist/installers/",
  "icon": "resources/Icon.ico",
  "tags": [
    "Utility"
  ]
}

And pass that instead with the config option:

$ electron-installer-windows --src dist/app-win32-x64/ --config config.json

Anyways, here's the full list of options:

src

Type: String Default: undefined

The path to the folder that contains your built Electron application.

dest

Type: String Default: undefined

The path to the folder that will contain your Windows installer.

rename

Type: Function Default: function (dest, src) { return path.join(dest, src); }

A function that renames all files generated by the task just before putting them in your dest folder.

options.name

Type: String Default: package.name

Name of the package (e.g., atom), used in the id field of the nuspec file.

options.productName

Type: String Default: package.productName || package.name

Name of the application (e.g., Atom), used in the title field of the nuspec file. It is also used as the description when signing your msi installer.

options.exe

Type: String Default: ${package.name}.exe || electron.exe

Relative path to the executable created by Electron Packager. Note that Electron Packager uses package.productName as the default.

options.description

Type: String Default: package.description

A description of the application, used in the description field of the nuspec file.

options.version

Type: String Default: package.version

Long description of the application, used in the version field of the nuspec file.

options.copyright

Type: String Default: package.copyright

Copyright details for the package, used in the copyright field of the nuspec file.

options.authors

Type: Array[String] Default: [package.author]

List of authors of the package, used in the authors field of the spec file.

options.owners

Type: Array[String] Default: [package.author]

List of owners of the package, used in the authors field of the spec file.

options.homepage

Type: String Default: package.homepage || package.author.url

URL of the homepage for the package, used in the projectUrl field of the spec file.

options.animation

Type: String Default: resources/animation.gif

The path to a .gif file to be displayed while installation is processing, used by Squirrel loading GIF

options.icon

Type: String Default: resources/icon.ico

The path to an .ico file used for the generated .exe installer.

options.iconNuget

Type: String Default: undefined

The path to an image file use as the icon for the NuGet package, used in the icon field of the spec file.

options.tags

Type: Array[String] Default: []

List of tags and keywords that describe the package, used in the tags field of the spec file.

options.noMsi

Type: Boolean Default: false

Whether an .msi installer should be created or not.

options.certificateFile

Type: String Default: undefined

The path to an Authenticode Code Signing Certificate.

options.certificatePassword

Type: String Default: undefined

Password to decrypt the certificate given in certificateFile.

options.signWithParams

Type: String Default: undefined

Parameters to pass to signtool. Overrides certificateFile and certificatePassword.

options.remoteReleases

Type: String Default: undefined

URL to your existing updates. If given, these will be downloaded to create delta updates.

If you are using Amazon S3 to store your releases, read the documentation for Squirrel.Windows on Amazon S3.

If you are using GitHub, read the documentation for Squirrel.Windows on GitHub.

Signing

Internet Explorer's SmartScreen Filter and antivirus programs may flag your package as malware if it's not signed. Luckily, signing your package with electron-installer-windows is pretty easy. Let's test the process with a self-signed certificate.

To generate the certificate, open the Developer Command Prompt for Visual Studio and execute the following:

$ makecert -sv my_private_key.pvk -n "CN=MyTestCertificate" my_test_certificate.cer -b 01/01/2016 -e 01/01/2026 -r
$ pvk2pfx -pvk my_private_key.pvk -spc my_test_certificate.cer -pfx my_signing_key.pfx -po my_password

Now we can tell electron-installer-windows to sign the packages that it generates with that certificate:

$ electron-installer-windows --src dist/app-win32-x64/ --dest dist/installers/ --certificateFile my_signing_key.pfx --certificatePassword my_password

Boom, that's it. Now get a standard code signing certificate from a real certificate authority!

Maintenance

Squirrel

Current version: 1.9.1

To update Squirrel to the latest version, head over to the releases page

NuGet

Current version: 5.4.0

To update NuGet to the latest version, head over to the releases page.

Meta

Contributors

License

Copyright (c) 2016 Daniel Perez Alvarez (unindented.org). This is free software and may be redistributed under the terms specified in the LICENSE file.

More Repositories

1

electron-builder

A complete solution to package and build a ready for distribution Electron app with โ€œauto updateโ€ support out of the box
TypeScript
13,564
star
2

devtron

[LOOKING FOR MAINTAINERS] An Electron DevTools Extension
JavaScript
1,728
star
3

spectron

DEPRECATED: ๐Ÿ”Ž Test Electron apps using ChromeDriver
JavaScript
1,677
star
4

electron-json-storage

๐Ÿ“ฆ Easily write and read user settings in Electron apps
JavaScript
1,433
star
5

electron-compile

DEPRECATED: Electron supporting package to compile JS and CSS in Electron applications
JavaScript
1,008
star
6

electron-webpack

Scripts and configurations to compile Electron applications using webpack
TypeScript
903
star
7

electron-prebuilt

๐ŸŽ‚ Retired project. See README
JavaScript
760
star
8

electron-webpack-quick-start

A bare minimum project structure to get started developing with electron-webpack.
JavaScript
729
star
9

electron-windows-store

๐Ÿ“ฆ Turn Electron Apps into Windows AppX Packages
JavaScript
678
star
10

electron-remote

DEPRECATED: Execute JavaScript in remote Electron processes, but more betterer
JavaScript
430
star
11

electron-installer-debian

Create a Debian package for your Electron app.
JavaScript
377
star
12

electron-wix-msi

๐Ÿ“€ Create traditional MSI installers for your Electron app
TypeScript
319
star
13

electron-installer-dmg

Create DMG installers for your electron apps using appdmg.
JavaScript
298
star
14

electron-spellchecker

Implement spellchecking, correctly
JavaScript
237
star
15

electron-builder-binaries

NSIS
172
star
16

electron-prebuilt-compile

electron-prebuilt with Babel and React built-in
JavaScript
169
star
17

electron-build-service

Package Electron applications in a distributable format on any platform for any platform
Go
138
star
18

electron-forge-templates

Templates bundled with Electron Forge <= 5 to create Electron apps using popular JavaScript frameworks
JavaScript
104
star
19

electron-installer-redhat

Create a Red Hat / RPM package for your Electron app.
JavaScript
81
star
20

electron-installer-snap

Build Snap packages for Electron applications
JavaScript
49
star
21

electrify

Step-by-step wizard to prepare Electron app for distribution, from packaging to auto-update.
TypeScript
48
star
22

electron-installer-zip

Create a ZIP file with support for symlinks required by Electron on macOS
JavaScript
46
star
23

welcome

Organization mission statement and contribution guidelines
45
star
24

electron-compilers

DEPRECATED: Compiler implementations for electron-compile
JavaScript
35
star
25

electron-installer-common

Common functionality for creating Node modules which create distributable Electron apps
JavaScript
9
star
26

electron-forge-container

Docker container for building Electron apps via Electron Forge
Dockerfile
7
star
27

create-electron-app

JavaScript
5
star
28

electron-forge-plugin-compile

Electron Compile plugin for Electron Forge
JavaScript
3
star
29

vue-cli-plugin-electron-forge

@vue/cli plugin to add Electron Forge
3
star