UNPKG

12.9 kBMarkdownView Raw
1Electron Forge
2--------------
3[![Linux/macOS Build Status](https://travis-ci.org/electron-userland/electron-forge.svg?branch=master)](https://travis-ci.org/electron-userland/electron-forge)
4[![Windows Build status](https://ci.appveyor.com/api/projects/status/79ae80nek1eucyy3?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/master/LICENSE)
9![status](https://img.shields.io/badge/Status-%20Ready%20for%20Awesome-red.svg)
10
11A complete tool for building modern Electron applications.
12
13Electron Forge unifies the existing (and well maintained) build tools for
14Electron development into a simple, easy to use package so that anyone can
15jump right in to Electron development.
16
17# Getting Started
18
19**Note**: Electron Forge requires Node 6 or above, plus git installed.
20
21```bash
22npm install -g electron-forge
23electron-forge init my-new-app
24cd my-new-app
25npm start
26```
27
28Alternatively, if you have a more recent version of `npm` or `yarn`, you can use
29[`npx`](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b),
30or
31[`yarn create`](https://yarnpkg.com/blog/2017/05/12/introducing-yarn/).
32
33```bash
34npx electron-forge init my-new-app
35# or
36yarn create electron-app my-new-app
37
38# then
39cd my-new-app
40npm start
41```
42
43# Project Goals
44
451. Starting with Electron should be as simple as a single command.
462. Developers shouldn't have to worry about `babel`, `browserify`, `webpack`,
47 native module rebuilding, etc. Everything should "just work" for them out
48 of the box.
493. Everything from creating the project to packaging the project for release
50 should be handled by one dependency in a standard way while still offering
51 users maximum choice and freedom.
52
53With these goals in mind, under the hood this project uses, among others:
54
55* [`electron-compile`](https://github.com/electron/electron-compile): a tool
56 that lets you use modern and futuristic languages inside Electron without
57 worrying about transpiling or build tooling.
58* [`electron-rebuild`](https://github.com/electron/electron-rebuild):
59 Automatically recompiles native Node.js modules against the correct
60 Electron version.
61* [Electron Packager](https://github.com/electron-userland/electron-packager):
62 Customizes and bundles your Electron app to get it ready for distribution.
63
64# Usage
65
66## Starting a new Project
67
68```bash
69npm install -g electron-forge
70electron-forge init my-new-project
71```
72
73This command will generate a brand new project folder and install all your Node
74module dependencies, so you will be all set to go. By default we will also
75install the `airbnb` linting modules. If you want to follow the `standard`
76linting rules instead, use the `--lintstyle=standard` argument.
77
78You can also start a project with your
79[favorite framework](https://electronforge.io/templates) with the `--template`
80argument. E.g. `--template=react`.
81
82If you'd like to have pre-made configuration files for Travis CI and AppVeyor CI to automatically
83build and deploy distributables to GitHub, use the `--copy-ci-files` argument.
84
85## Importing an existing Project
86
87```bash
88electron-forge import existing-project-directory
89```
90
91Given an existing Electron project, this command will attempt to interactively
92navigate through the process of importing it to the Electron Forge format, so
93the commands listed below can be used. This includes being prompted to remove
94existing Electron build tools in favor of Electron Forge equivalents.
95
96## Launching your Project
97
98```bash
99electron-forge start
100```
101
102Any arguments after "start" will be passed through to your application when
103it's launched.
104
105## Packaging your Project
106
107```bash
108electron-forge package
109```
110
111Yes, it really is that simple. If you want to specify platform / arch, use the
112`--platform=<platform>` and `--arch=<arch>` arguments.
113
114## Generating a distributable for your Project
115
116```bash
117electron-forge make
118```
119
120This will generate platform specific distributables (installers, distribution
121packages, etc.) for you. By default, you can only generate distributables
122for your current platform. If you want to specify platform / arch, use the
123`--platform=<platform>` and `--arch=<arch>` arguments, but _please note that
124some distributables are not available to be built on anything but the platform
125that is targeted. For example, `appx` (Windows Store) distributables can only
126be built on Windows._
127
128## Linting your Project
129
130```bash
131electron-forge lint
132```
133
134## Publishing your Project
135
136```bash
137electron-forge publish
138```
139
140This will `make` your project and publish any generated artifacts. By default it will publish to
141GitHub, but you can change the publish target(s) with `--target=YourTarget,YourTarget2`, where the
142value is a comma-separated list of targets.
143
144# Config
145
146Once you have generated a project, your `package.json` file will have some
147default `forge` configuration. Below is the reference structure for this
148config object:
149
150```javascript
151{
152 "make_targets": {
153 "win32": ["squirrel"], // An array of win32 make targets
154 "darwin": ["zip", "dmg"], // An array of darwin make targets
155 "linux": ["deb", "rpm", "flatpak"] // An array of linux make targets
156 },
157 "electronPackagerConfig": {},
158 "electronWinstallerConfig": {},
159 "electronInstallerDMG": {},
160 "electronInstallerFlatpak": {},
161 "electronInstallerDebian": {},
162 "electronInstallerRedhat": {}
163}
164```
165
166## Possible `make` targets
167
168| Target Name | Available Platforms | Description | Configurable Options | Default? | Requirements |
169|-------------|---------------------|-------------|----------------------|----------|--------------|
170| `zip` | All | Zips your packaged application | None | Yes | `zip` on Darwin/Linux |
171| `squirrel` | Windows | Generates an installer and `.nupkg` files for Squirrel.Windows | [`electronWinstallerConfig`](https://github.com/electron/windows-installer#usage) | Yes | |
172| `appx` | Windows | Generates a Windows Store package | [`windowsStoreConfig`](https://github.com/felixrieseberg/electron-windows-store#programmatic-usage) | No | |
173| `dmg` | Darwin | Generates a DMG file | [`electronInstallerDMG`](https://github.com/mongodb-js/electron-installer-dmg#api) | No | |
174| `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) |
175| `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) |
176| `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) |
177
178## Configuring `package`
179
180You can set `electronPackagerConfig` with any of the options from
181[Electron Packager](https://github.com/electron-userland/electron-packager/blob/master/docs/api.md), except:
182
183* `arch`
184* `asar.unpack` (use `asar.unpackDir` instead)
185* `dir`
186* `electronVersion` (uses the exact version specified for `electron-prebuilt-compile` in your `devDependencies`)
187* `out`
188* `platform`
189* `quiet`
190
191**NOTE:** You can also set your `forge` config property of your package.json to point to a JS file that exports the config object:
192
193```js
194{
195 ...
196 "config": {
197 "forge": "./forge.config.js"
198 }
199 ...
200}
201```
202
203**NOTE:** If you use the JSON object then the `afterCopy` and `afterExtract` options are mapped to `require`
204calls internally, so provide a path to a file that exports your hooks and they will still run. If you use
205the JS file method mentioned above then you can use functions normally.
206
207## Possible `publish` targets
208
209| Target Name | Description | Required Config |
210|-------------|-------------|-----------------|
211| 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` |
212| 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` |
213| [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. The channel is determined from the current version. | `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 |
214
215For example:
216
217```javascript
218// github
219{
220 // Assume the GitHub repository is at https://github.com/username/repo
221 "github_repository": {
222 "owner": "username",
223 "name": "repo"
224 }
225}
226
227// s3
228{
229 "s3": {
230 "accessKeyId": "<AWS_ACCESS_KEY>",
231 "bucket": "my_bucket_name",
232 "public": true
233 }
234}
235
236// Electron Release Server
237{
238 "electronReleaseServer": {
239 "baseUrl": "https://update.mysite.com",
240 "username": "admin",
241 "password": "no_one_will_guess_this"
242 }
243}
244```
245
246## Custom `make` and `publish` targets
247
248You can make your own custom targets for the `make` and `publish` targets. If you publish them as `electron-forge-publisher-{name}` or `electron-forge-maker-{name}` you can then just specify `{name}` as your make / publish target. The API for each is documented below.
249
250### API for `make` targets
251
252You must export a Function that returns a Promise. Your function will be called with the following parameters.
253
254* `appDir` - The directory containing the packaged application
255* `appName` - The productName of the application
256* `targetArch` - The target architecture of the make command
257* `forgeConfig` - An object representing the users forgeConfig
258* `packageJSON` - An object representing the users package.json file
259
260Your promise must resolve with an array of the artifacts you generated.
261
262### API for `publish` targets
263
264You must export a Function that returns a Promise. Your function will be called with the following parameters.
265
266* artifactPaths - An array of absolute paths to artifacts to publish
267* packageJSON - An object representing the users package.json file
268* forgeConfig - An object representing the users forgeConfig
269* authToken - The value of `--auth-token`
270* tag - The value of `--tag`
271* platform - The platform you are publishing for
272* arch - The arch you are publishing for
273
274You should use `ora` to indicate your publish progress.
275
276## Debugging your application through VS Code
277
278Debugging your Electron main process through VS Code is ridiculously
279easy with Forge. Simply add this as a launch config in VSCode and you're
280good to go.
281
282```js
283{
284 "type": "node",
285 "request": "launch",
286 "name": "Electron Main",
287 "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-forge-vscode-nix",
288 "windows": {
289 "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-forge-vscode-win.cmd"
290 },
291 // runtimeArgs will be passed directly to your Electron application
292 "runtimeArgs": [
293 "foo",
294 "bar"
295 ],
296 "cwd": "${workspaceRoot}"
297}
298```