Skip to content

Commit 33d5abd

Browse files
committed
docs(config): document extraResource for runtime assets
1 parent 7ed40ed commit 33d5abd

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

config/configuration.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,33 @@ If you want to specify a platform/architecture combination for any build command
123123
See the [#build-commands](../cli.md#build-commands "mention") documentation for more details.
124124
{% endhint %}
125125

126+
{% hint style="info" %}
127+
To ship runtime assets that live outside your bundled source code (for example, a tray icon or other binary file referenced at runtime), use [`extraResource`](https://electron.github.io/packager/main/interfaces/Options.html#extraresource). Files listed here are copied into the platform's resources directory (next to `app.asar`) and are available at runtime via `process.resourcesPath`.
128+
129+
{% code title="forge.config.js" %}
130+
```javascript
131+
module.exports = {
132+
packagerConfig: {
133+
extraResource: ['./assets/tray-icon.png']
134+
}
135+
};
136+
```
137+
{% endcode %}
138+
139+
In the main process, resolve the file with `process.resourcesPath` when the app is packaged:
140+
141+
```javascript
142+
const path = require('path');
143+
const { app, Tray } = require('electron');
144+
145+
const iconPath = app.isPackaged
146+
? path.join(process.resourcesPath, 'tray-icon.png')
147+
: path.join(__dirname, '..', 'assets', 'tray-icon.png');
148+
149+
const tray = new Tray(iconPath);
150+
```
151+
{% endhint %}
152+
126153
### Electron Rebuild config
127154

128155
The top level property `rebuildConfig` on the configuration object maps directly to the options sent to [`@electron/rebuild`](https://github.com/electron/rebuild) during both the [#package](../cli.md#package "mention") and [#start](../cli.md#start "mention") commands in Electron Forge.

0 commit comments

Comments
 (0)