Packaging and distributing apps is an integral part of the development process of a desktop application. Since Electron is a cross-platform desktop application development framework, packaging and distribution of apps for all the platforms should also be a seamless experience.
The electron community has created a project, electron-packager that takes care of the same for us. It allows us to package and distribute our Electron app with OS-specific bundles (.app, .exe etc) via JS or CLI.
Electron Packager runs on the following host platforms −
It generates executables/bundles for the following target platforms −
Install the electron packager using −
# for use in npm scripts $ npm install electron-packager --save-dev # for use from cli $ npm install electron-packager -g
In this section, we will see how to run the packager from the command line. The basic form of the command is −
electron-packager <sourcedir> <appname> --platform=<platform> --arch=<arch> [optional flags...]
This will −
Find or download the correct release of Electron.
Use that version of Electron to create a app in <output-folder>/<appname>-<platform>-<arch>.
--platform and --arch can be omitted, in two cases. If you specify --all instead, bundles for all valid combinations of target platforms/architectures will be created. Otherwise, a single bundle for the host platform/architecture will be created.