Electron Packager
A Electron packager that packages your .app bundle smaller than 1 MB.
How does it works?
The packaged .app bundle doesn't include (e.g. Electron Framework.framework) huge files like big frameworks but store them globally in the library of the system.
These global required resources are accessible from every .app that is packaged in this way. Therefore you just have to install the required resources one times.
Works out of the box
Yes. The packaged .app bundle contains a small downloading process for the required resources. The specific mirror is the github repository of electron.
Install
npm install electron_packager -g
Command Line Interface
All CLI arguments are optional except the src.
electron_packager src=/path/to/app/folder
Argument | Value | Default |
---|
src | /path/to/app | Required |
target | /path/to/output | Parent folder of src |
platform | 'darwin' || 'win' || 'linux' || | 'darwin' |
name | Custom Name | {package.json->name} |
icon | /path/to/icon/file | false |
identifier | com.developer.myapp | com.{package.json->author}.{package.json->name} |
Please make sure that the packager actually only suppports macOS (darwin)!
Support for windows and linux is in development.
Functionality
The functionality is very modular.
In AppBundle.app/Contents/Bundle.json
you'll find a file that contains all outsourced resources. This resources will be deleted in your app bundle and therefore accessed using the library. In this file, everything is described. That means, which resources are outsourced and where the global electron app bundle is stored. (e.g. ~/Library/Electron
). Normally you shouldn't touch this file because it outsources everything that makes sense.
Process in detail
If your app starts, it will look at the destination
and try to open itself with the resources stored there in the Electron.app
bundle. If the version of your Bundle.json
is higher than the version of the (in destination
stored) Electron.app
and its resources or if there isn't any instance of a Electron.app
a download progress will begin that downloads the latest version of Electron and saves it to destination
. This progress will use GitHub as mirror and the npm registry for information about electron in general.
Just d nothing. When your electron instance is installed, every app that is packaged in this way can use this global electron instance. (Of course, only if the destination
in Bundle.json
points on the default folder ~/Library/Electron
which should be the case beacuse you shouldn't touch it).
This is, how the Bundle.json normally looks like:
{
"electron": {
"version": "v1.6.11",
"destination": "~/Library/Electron",
"bundle": "Electron.app",
"resources": [
"Frameworks/Electron Framework.framework",
"Frameworks/Squirrel.framework",
"Frameworks/Mantle.framework",
"Frameworks/ReactiveCocoa.framework",
"Resources/electron.asar"
]
},
"executable": "MacOS/Electron"
}
Important
The property version
of electron
is automatically generated. It's required to update the global electron instance when your app needs a newer one. It updates automatically to the newest one, not to the version of your app. That means, if you use a version
in your Bundle.json
that is higher than the newest one, your app will open a download progress every time you try to open it. But because of the impossibility to use a electron version that doesn't exists, you just have to keep in mind that you shouldn't touch this file. And if you touch it, just change the resources
. Please keep in mind that every resource that is not declared in your Bundle.json
wouldn't be outsources. Therefore you have to package it. But be careful because it can be dangerous to outsource some files and others not because they dependent from each other and if the versions of your app's (not outsourced) resources are not the newest one but some resources you outsource in the system are the newest one, something could go wrong. For example, think of the case you don't outsource Electron Framework.framework
but not Mantle.framework
. That means, your app will use Mantle.framework
from your apps directory (which could be very old) and Electron Framework.framework
from ~/Library/Electron/...
(which could be very new). And if this versions aren't compatible, your app wouldn't work.
And because of that, just don't touch it. Just don't do it if there is no special reason for it.
Module
const packager = require('electron_packager');
packager.package({
source: "path/to/your/app",
platform: "darwin",
target: "path/to/your/destination",
name: "You App Name",
icon: "path/to/your/custom/icon.icns",
identifier: "com.yourCompany.yourAppName"
});