Electron
makes it pretty easy to run angular2-instagram
as desktop app. To create a standalone executable we're using two packages:
electron-builder
electron-packager
We're using both for educational purposes, a single one of those would suffice.
To configure electron
we need to create an entry file that will be run when calling the electron
command. You can find it here on /src/app/electron/electron.js
.
npm run electron:dev
will startwebpack-dev-server
along withelectron
with hot reloading and devtools activatednpm run electron:prod
will first build the app following the standard production webpack pipeline, then it will copy/package.json
and/src/app/electron/electron.js
to the output/public
directory and finally runelectron
. Webpack is not running in--watch
mode so changes won't be rebuilt
This project uses both electron-packager
and electron-builder
to create the standalone app. Consider that you might need additional tools in order to package the app for multiple platforms using a single OS (eg. to package for Windows using Linux you will need Wine).
By running npm run electron:builder
the app will be built in production
mode with webpack
and the resulting files under the /public
folder will be packaged to create the standalone electron
app. If no other parameter is set, the app will be packaged for the current OS and architecture (eg. macOS 64bit) and will be found under the /dist
folder.
If you want, for example, pack the app for Windows 32bit you could do npm run electron:builder -- -w --ia32
. If you want to build for all 64bit platforms you should run npm run electron:builder -- -lwm --x64
.
The configuration that electron-builder
uses to create the package is in the build
section of package.json
.
Following are some useful information to keep in mind:
appId
is a general name in the form ofcom.electron.app-name
category
is the category in which the app can be identified, here is a list of possible categoriesbuildResources
is the folder where backgrounds and icons are stored: abackground.png
used as macOS DMG background, app icons in the form oficon.icns
(macOS app icon) andicon.ico
(Windows app icon) and the same icons in.png
format named24x24.png
,32x32.png
,48x48.png
,64x64.png
,128x128.png
,256x256.png
each with the corresponding dimensionsfiles
is a list of files and folders to be packaged in the final app, defining them here also won't copy all thenode_modules
andsrc
fileslinux
is just an example to show you can define specific target images/formats for the packaged app
There is much more to it, for full documentation and examples here are some useful links:
By running npm run electron:packager
the following steps will happen:
- the app will be built in
production
mode withwebpack
- the
electron.js
configuration file will be copied with its folder structure inside/public
folder electron-packager
will package all the contents of the/public
folder and create an executable file under the/dist/...
folder
If no other parameter is set, the app will be packaged for the current OS and architecture (eg. macOS 64bit). To packager for multiple OS and architecture you can use the --platform=<platform>
and --arch=<arch>
respectively.
- For a full documentation please refer to the
electron-packager
Github page. - For a detailed list of all the available parameters click here
We are using electron-builder
via the script npm run electron:publish
command to create a release
in the angular2-instagram
repository and attach the standalone desktop app.
This is the step by step process we follow:
- first created a Github token with repo access
- locally set the env variable with eg.
export GH_TOKEN="<TOKEN_HERE>"
- update the
version
inpackage.json
, this will also be the name (prepended with av
eg.0.0.2
will becomev0.0.2
) of therelease
that will be created in Github - run
npm run build:electron
if theelectron
production
version has not been built yet - run
npm run electron:publish
to push the package to Github - go to the Github release section of the repository, edit the description and title of the release and publish it, since it was initially created by
electron-builder
as adraft
For more info on programmatically publishing the executable on other sources you can have a look at the official documentation on electron-builder.