1 | Electron Forge
|
2 | --------------
|
3 | [![Linux/macOS Build Status](https://travis-ci.org/electron-userland/electron-forge.svg?branch=5.x)](https://travis-ci.org/electron-userland/electron-forge)
|
4 | [![Windows Build status](https://ci.appveyor.com/api/projects/status/79ae80nek1eucyy3/branch/5.x?svg=true)](https://ci.appveyor.com/project/electron-userland/electron-forge)
|
5 | [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
|
6 | [![npm version](https://badge.fury.io/js/electron-forge.svg)](https://www.npmjs.com/package/electron-forge)
|
7 | [![npm](https://img.shields.io/npm/dt/electron-forge.svg?maxAge=2592000)](https://www.npmjs.com/package/electron-forge)
|
8 | [![license](https://img.shields.io/github/license/electron-userland/electron-forge.svg)](https://github.com/electron-userland/electron-forge/blob/5.x/LICENSE)
|
9 | ![status](https://img.shields.io/badge/Status-%20Ready%20for%20Awesome-red.svg)
|
10 |
|
11 | A complete tool for building modern Electron applications.
|
12 |
|
13 | Electron Forge unifies the existing (and well maintained) build tools for
|
14 | Electron development into a simple, easy to use package so that anyone can
|
15 | jump right in to Electron development.
|
16 |
|
17 | ----
|
18 |
|
19 | [Website](https://electronforge.io) |
|
20 | [Goals](#project-goals) |
|
21 | [Usage](#usage) |
|
22 | [Configuration](#config) |
|
23 | [Support](https://github.com/electron-userland/electron-forge/blob/master/SUPPORT.md) |
|
24 | [Contributing](https://github.com/electron-userland/electron-forge/blob/master/CONTRIBUTING.md) |
|
25 | [Changelog](https://github.com/electron-userland/electron-forge/blob/master/CHANGELOG.md)
|
26 |
|
27 | # Getting Started
|
28 |
|
29 | **Note**: Electron Forge requires Node 6 or above, plus git installed.
|
30 |
|
31 | ```bash
|
32 | npm install -g electron-forge
|
33 | electron-forge init my-new-app
|
34 | cd my-new-app
|
35 | npm start
|
36 | ```
|
37 |
|
38 | Alternatively, if you have a more recent version of `npm` or `yarn`, you can use
|
39 | [`npx`](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b),
|
40 | or
|
41 | [`yarn create`](https://yarnpkg.com/blog/2017/05/12/introducing-yarn/).
|
42 |
|
43 | ```bash
|
44 | npx electron-forge init my-new-app
|
45 | # or
|
46 | yarn create electron-app my-new-app
|
47 |
|
48 | # then
|
49 | cd my-new-app
|
50 | npm start
|
51 | ```
|
52 |
|
53 | # Project Goals
|
54 |
|
55 | 1. Starting with Electron should be as simple as a single command.
|
56 | 2. Developers shouldn't have to worry about `babel`, `browserify`, `webpack`,
|
57 | native module rebuilding, etc. Everything should "just work" for them out
|
58 | of the box.
|
59 | 3. Everything from creating the project to packaging the project for release
|
60 | should be handled by one dependency in a standard way while still offering
|
61 | users maximum choice and freedom.
|
62 |
|
63 | With these goals in mind, under the hood this project uses, among others:
|
64 |
|
65 | * [`electron-compile`](https://github.com/electron/electron-compile): a tool
|
66 | that lets you use modern and futuristic languages inside Electron without
|
67 | worrying about transpiling or build tooling.
|
68 | * [`electron-rebuild`](https://github.com/electron/electron-rebuild):
|
69 | Automatically recompiles native Node.js modules against the correct
|
70 | Electron version.
|
71 | * [Electron Packager](https://github.com/electron-userland/electron-packager):
|
72 | Customizes and bundles your Electron app to get it ready for distribution.
|
73 |
|
74 | # Usage
|
75 |
|
76 | ## Starting a new Project
|
77 |
|
78 | ```bash
|
79 | npm install -g electron-forge
|
80 | electron-forge init my-new-project
|
81 | ```
|
82 |
|
83 | This command will generate a brand new project folder and install all your Node
|
84 | module dependencies, so you will be all set to go. By default we will also
|
85 | install the `airbnb` linting modules. If you want to follow the `standard`
|
86 | linting rules instead, use the `--lintstyle=standard` argument.
|
87 |
|
88 | You can also start a project with your
|
89 | [favorite framework](https://electronforge.io/templates) with the `--template`
|
90 | argument. E.g. `--template=react`.
|
91 |
|
92 | If you'd like to have pre-made configuration files for Travis CI and AppVeyor CI to automatically
|
93 | build and deploy distributables to GitHub, use the `--copy-ci-files` argument.
|
94 |
|
95 | ## Importing an existing Project
|
96 |
|
97 | ```bash
|
98 | electron-forge import existing-project-directory
|
99 | ```
|
100 |
|
101 | Given an existing Electron project, this command will attempt to interactively
|
102 | navigate through the process of importing it to the Electron Forge format, so
|
103 | the commands listed below can be used. This includes being prompted to remove
|
104 | existing Electron build tools in favor of Electron Forge equivalents.
|
105 |
|
106 | ## Launching your Project
|
107 |
|
108 | ```bash
|
109 | electron-forge start
|
110 | ```
|
111 |
|
112 | Any arguments after "start" will be passed through to your application when
|
113 | it's launched.
|
114 |
|
115 | ## Packaging your Project
|
116 |
|
117 | ```bash
|
118 | electron-forge package
|
119 | ```
|
120 |
|
121 | Yes, it really is that simple. If you want to specify platform / arch, use the
|
122 | `--platform=<platform>` and `--arch=<arch>` arguments.
|
123 |
|
124 | ## Generating a distributable for your Project
|
125 |
|
126 | ```bash
|
127 | electron-forge make
|
128 | ```
|
129 |
|
130 | This will generate platform specific distributables (installers, distribution
|
131 | packages, etc.) for you. By default, you can only generate distributables
|
132 | for your current platform. If you want to specify platform / arch, use the
|
133 | `--platform=<platform>` and `--arch=<arch>` arguments, but _please note that
|
134 | some distributables are not available to be built on anything but the platform
|
135 | that is targeted. For example, `appx` (Windows Store) distributables can only
|
136 | be built on Windows._
|
137 |
|
138 | ## Linting your Project
|
139 |
|
140 | ```bash
|
141 | electron-forge lint
|
142 | ```
|
143 |
|
144 | ## Publishing your Project
|
145 |
|
146 | ```bash
|
147 | electron-forge publish
|
148 | ```
|
149 |
|
150 | This will `make` your project and publish any generated artifacts. By default it will publish to
|
151 | GitHub, but you can change the publish target(s) with `--target=YourTarget,YourTarget2`, where the
|
152 | value is a comma-separated list of targets.
|
153 |
|
154 | # Config
|
155 |
|
156 | Once you have generated a project, your `package.json` file will have some
|
157 | default `forge` configuration. Below is the reference structure for this
|
158 | config object:
|
159 |
|
160 | ```javascript
|
161 | {
|
162 | "make_targets": {
|
163 | "win32": ["squirrel"], // An array of win32 make targets
|
164 | "darwin": ["zip", "dmg"], // An array of darwin make targets
|
165 | "linux": ["deb", "rpm", "flatpak", "snap"] // An array of linux make targets
|
166 | },
|
167 | "electronPackagerConfig": {},
|
168 | "electronRebuildConfig": {},
|
169 | "electronWinstallerConfig": {},
|
170 | "electronInstallerDMG": {},
|
171 | "electronInstallerFlatpak": {},
|
172 | "electronInstallerDebian": {},
|
173 | "electronInstallerRedhat": {},
|
174 | "electronInstallerSnap": {}
|
175 | }
|
176 | ```
|
177 |
|
178 | ## Possible `make` targets
|
179 |
|
180 | | Target Name | Available Platforms | Description | Configurable Options | Default? | Requirements |
|
181 | |-------------|---------------------|-------------|----------------------|----------|--------------|
|
182 | | `zip` | All | Zips your packaged application | None | Yes | `zip` on Darwin/Linux |
|
183 | | `squirrel` | Windows | Generates an installer and `.nupkg` files for Squirrel.Windows | [`electronWinstallerConfig`](https://github.com/electron/windows-installer#usage) | Yes | |
|
184 | | `appx` | Windows | Generates a Windows Store package | [`windowsStoreConfig`](https://github.com/felixrieseberg/electron-windows-store#programmatic-usage) | No | |
|
185 | | `wix` | Windows | Generates a traditional MSI file | [`electronWixMSIConfig`](https://github.com/felixrieseberg/electron-wix-msi#configuration) | No | [Wix Toolit](https://github.com/felixrieseberg/electron-wix-msi#prerequisites) |
|
186 | | `dmg` | Darwin | Generates a DMG file | [`electronInstallerDMG`](https://github.com/mongodb-js/electron-installer-dmg#api) | No | |
|
187 | | `deb` | Linux | Generates a Debian package | [`electronInstallerDebian`](https://github.com/unindented/electron-installer-debian#options) | Yes | [`fakeroot` and `dpkg`](https://github.com/unindented/electron-installer-debian#requirements) |
|
188 | | `rpm` | Linux | Generates an RPM package | [`electronInstallerRedhat`](https://github.com/unindented/electron-installer-redhat#options) | Yes | [`rpm`](https://github.com/unindented/electron-installer-redhatn#requirements) |
|
189 | | `flatpak` | Linux | Generates a [Flatpak](http://flatpak.org/) file | [`electronInstallerFlatpak`](https://github.com/endlessm/electron-installer-flatpak#options) | No | [`flatpak-builder`](https://github.com/endlessm/electron-installer-flatpak#requirements) |
|
190 | | `snap` | Linux | Generates a [Snap](https://snapcraft.io/) file | [`electronInstallerSnap`](https://github.com/electron-userland/electron-installer-snap/blob/master/docs/api.md#options) | No | [`snapcraft`](https://snapcraft.io/docs/build-snaps/#install-snapcraft) |
|
191 |
|
192 | ## Configuring `package`
|
193 |
|
194 | You can set `electronPackagerConfig` with any of the options from
|
195 | [Electron Packager](https://github.com/electron-userland/electron-packager/blob/master/docs/api.md), except:
|
196 |
|
197 | * `all`
|
198 | * `arch` (use the `--arch` Forge command line argument instead, so it's available to all of Forge)
|
199 | * `asar.unpack` (use `asar.unpackDir` instead)
|
200 | * `dir` (use the `cwd` Forge command line argument instead, so it's available to all of Forge)
|
201 | * `electronVersion` (uses the exact version specified for `electron-prebuilt-compile` in your `devDependencies`)
|
202 | * `out`
|
203 | * `platform` (use the `--platform` Forge command line argument instead, so it's available to all of Forge)
|
204 | * `quiet`
|
205 |
|
206 | You can set `electronRebuildConfig` with any of the options from
|
207 | [Electron Rebuild](https://github.com/electron/electron-rebuild#how-can-i-integrate-this-into-grunt--gulp--whatever), except:
|
208 |
|
209 | * `electronVersion`/`--version` (uses the exact version specified for `electron-prebuilt-compile` in your `devDependencies`)
|
210 | * `arch`/`--arch` (use the `--arch` Forge command line argument instead, so it's available to all of Forge)
|
211 | * `buildPath`/`--module-dir` (uses your project's `node_modules`)
|
212 |
|
213 | **NOTE:** You can also set your `forge` config property of your package.json to point to a JS file that exports the config object:
|
214 |
|
215 | ```js
|
216 | {
|
217 | ...
|
218 | "config": {
|
219 | "forge": "./forge.config.js"
|
220 | }
|
221 | ...
|
222 | }
|
223 | ```
|
224 |
|
225 | **NOTE:** If you use the JSON object then the `afterCopy` and `afterExtract` options are mapped to `require`
|
226 | calls internally, so provide a path to a file that exports your hooks and they will still run. If you use
|
227 | the JS file method mentioned above then you can use functions normally.
|
228 |
|
229 | ## Possible `publish` targets
|
230 |
|
231 | | Target Name | Description | Required Config |
|
232 | |-------------|-------------|-----------------|
|
233 | | GitHub Releases - `github` | Makes a new release for the current version (if required) and uploads the make artifacts as release assets | `process.env.GITHUB_TOKEN` - A personal access token with access to your releases <br />`forge.github_repository.owner` - The owner of the GitHub repository<br />`forge.github_repository.name` - The name of the GitHub repository <br />`forge.github_repository.draft` - Create the release as a draft, defaults to `true` <br />`forge.github_repository.prerelease` - Identify the release as a prerelease, defaults to `false` <br />`forge.github_repository.options` - An `Object` of [connection options](https://github.com/octokit/rest.js#usage), e.g., GitHub Enterprise settings or HTTP proxy URL |
|
234 | | Amazon S3 - `s3` | Uploads your artifacts to the given S3 bucket | `process.env.ELECTRON_FORGE_S3_SECRET_ACCESS_KEY` - Your secret access token for your AWS account _(falls back to the standard `AWS_SECRET_ACCESS_KEY` environment variable)_<br />`forge.s3.accessKeyId` - Your access key for your AWS account _(falls back to the standard `AWS_ACCESS_KEY_ID` environment variable)_<br />`forge.s3.bucket` - The name of the S3 bucket to upload to<br />`forge.s3.folder` - The folder path to upload to inside your bucket, defaults to your application version<br />`forge.s3.public` - Whether to make the S3 upload public, defaults to `false` |
|
235 | | [Electron Release Server](https://github.com/ArekSredzki/electron-release-server) - `electron-release-server` | Makes a new release for the current version and uploads the artifacts to the correct platform/arch in the given version. If the version already exists no upload will be performed. | `forge.electronReleaseServer.baseUrl` - The base URL of your release server, no trailing slash<br />`forge.electronReleaseServer.username` - The username for the admin panel on your server<br />`forge.electronReleaseServer.password` - The password for the admin panel on your server<br />`forge.electronReleaseServer.channel` - If specified, the release channel name. Defaults to `stable`/`alpha`/`beta` depending on the app version |
|
236 | | [Snapcraft](https://snapcraft.io/store/) - `snapStore` | Uploads generated Snaps to the Snap Store. | `forge.snapStore.release` - If specified, a comma-separated list of channels to release to. |
|
237 |
|
238 | For example:
|
239 |
|
240 | ```javascript
|
241 | // github
|
242 | {
|
243 | // Assume the GitHub repository is at https://github.com/username/repo
|
244 | "github_repository": {
|
245 | "owner": "username",
|
246 | "name": "repo"
|
247 | }
|
248 | }
|
249 |
|
250 | // s3
|
251 | {
|
252 | "s3": {
|
253 | "accessKeyId": "<AWS_ACCESS_KEY>",
|
254 | "bucket": "my_bucket_name",
|
255 | "public": true
|
256 | }
|
257 | }
|
258 |
|
259 | // Electron Release Server
|
260 | {
|
261 | "electronReleaseServer": {
|
262 | "baseUrl": "https://update.mysite.com",
|
263 | "username": "admin",
|
264 | "password": "no_one_will_guess_this"
|
265 | }
|
266 | }
|
267 |
|
268 | // Snap Store
|
269 | {
|
270 | "snapStore": {
|
271 | "release": "candidate,beta"
|
272 | }
|
273 | }
|
274 | ```
|
275 |
|
276 | ## Custom `make` and `publish` targets
|
277 |
|
278 | You can make your own custom targets for the `make` and `publish` targets. If you publish them as
|
279 | `electron-forge-publisher-{name}` or `electron-forge-maker-{name}`, they can be added to the app's
|
280 | `devDependencies` and can be specified as `{name}` in the make / publish targets. Publicly published
|
281 | third-party [makers](https://www.npmjs.com/search?q=electron%2Dforge%2Dmaker) and
|
282 | [publishers](https://www.npmjs.com/search?q=electron-forge-publisher) are available in the NPM registry.
|
283 |
|
284 | The API for each target type is documented below.
|
285 |
|
286 | ### API for `make` targets
|
287 |
|
288 | You must export a Function that returns a Promise. Your function will be called with the following parameters.
|
289 |
|
290 | * `appDir` - The directory containing the packaged application
|
291 | * `appName` - The productName of the application
|
292 | * `targetArch` - The target architecture of the make command
|
293 | * `forgeConfig` - An object representing the users forgeConfig
|
294 | * `packageJSON` - An object representing the users package.json file
|
295 |
|
296 | Your promise must resolve with an array of the artifacts you generated.
|
297 |
|
298 | ### API for `publish` targets
|
299 |
|
300 | You must export a `Function` that returns a `Promise`. Your function will be called with the following keyword parameters:
|
301 |
|
302 | * `dir` - The application directory
|
303 | * `artifacts` - An array of absolute paths to artifacts to publish
|
304 | * `packageJSON` - An object representing the user's `package.json` file
|
305 | * `forgeConfig` - An object representing the user's [`forgeConfig`](#config)
|
306 | * `authToken` - The value of `--auth-token`
|
307 | * `tag` - The value of `--tag`
|
308 | * `platform` - The platform you are publishing for
|
309 | * `arch` - The arch you are publishing for
|
310 |
|
311 | You should use `ora` to indicate your publish progress.
|
312 |
|
313 | ## Debugging your application on the command line
|
314 |
|
315 | If you're using Electron 1.7 or later, you can specify the `--inspect-electron` flag, which will
|
316 | set the [Electron `--inspect` flag](http://electronjs.org/docs/tutorial/debugging-main-process#--inspectport)
|
317 | with the default debugger port.
|
318 |
|
319 | For example:
|
320 |
|
321 | ```shell
|
322 | electron-forge start --inspect-electron
|
323 | ```
|
324 |
|
325 | ## Debugging your application through VS Code
|
326 |
|
327 | Debugging your Electron main process through VS Code is ridiculously
|
328 | easy with Forge. Simply add this as a launch config in VSCode and you're
|
329 | good to go.
|
330 |
|
331 | ```js
|
332 | {
|
333 | "type": "node",
|
334 | "request": "launch",
|
335 | "name": "Electron Main",
|
336 | "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-forge-vscode-nix",
|
337 | "windows": {
|
338 | "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-forge-vscode-win.cmd"
|
339 | },
|
340 | // runtimeArgs will be passed directly to your Electron application
|
341 | "runtimeArgs": [
|
342 | "foo",
|
343 | "bar"
|
344 | ],
|
345 | "cwd": "${workspaceRoot}"
|
346 | }
|
347 | ```
|