This is (hopefully) the simplest way to load contents of all active
BrowserWindows within electron when the source files are changed.
Disclaimer: this module is in its very early stages and the logic is still not mature enough.
npm install electron-reload
Just initialize this module with desired glob or file path to watch and let it refresh electron browser windows as targets are changed:
'use strict';const app BrowserWindow = ;__dirname;// Standard stuffapp;
Note that the above code only refreshes
WebContents of all
BrowserWindows. So if you want to have a hard reset (starting a new electron process) you can just pass the path to the electron executable in the
options object. For example if you already have electron pre-built installed you could just do
You could also use the (relatively) new
electron package, but you should specify the path directly (no
const path =__dirnameelectron: path;
If your app overrides some of the default
close actions (e.g. closing the last app window hides the window instead of quitting the app) then the default
electron-reload hard restart could leave you with multiple instances of your app running. In these cases you can change the default hard restart action from
app.exit() by specifying the hard reset method in the electron-reload options:
const path =__dirnameelectron: pathhardResetMethod: 'exit';
paths: a file, directory or glob pattern to watch
electronproperty pointing to electron executables. (default:
Why this module?
Simply put, I was tired and confused by all other available modules which are so complicated* for such an uncomplicated task!
* e.g. start a local HTTP server, publish change events through a WebSocket, etc.!
If you want to have least effort when developing electron packages, take a look at neutron!
- 1.2.5: Upgrade dependencies (fix vulnerabilities)
- 1.2.4: Use
index.jsas fallback if
mainis not defined in
- 1.2.3: Fix multiple instances on restart
- 1.2.2: Fix
- 1.2.1: Remove logging from production code (d'oh)
- 1.2.0: Allow hard reset in multiple browser windows
- 1.1.0: Add
app.exit()in addition to
app.quit()for hard resets
- 1.0.3: Fix hard reset bug
- 1.0.2: Detach child so that killing parent doesn't kill it (on windows)
- 1.0.1: Replace
- 1.0.0: Adapt to Electron 1.0 new API
- 0.3.0: Use new method of accessing
- 0.2.0: Use new electrons (> v0.32.3)