Simple auto-reloading for Electron apps during development using webpack
It just works. When files used in the main process are changed, the app is restarted, and when files used in the browser window are changed, the page is reloaded.
Note that it will only work if you bundle your codebase in a single file using webpack or another bundler.
$ npm install --save-dev electron-reloader
Requires Electron 5 or later.
The following must be included in the app entry file, usually named index.js
:
try {
require('@vitrine/electron-hot-reloader')(module);
} catch (_) {}
You have to pass the module
object so we can read the module graph and figure out which files belong to the main process.
The try/catch
is needed so it doesn't throw Cannot find module '@vitrine/electron-hot-reloader'
in production.
Type: string
The path of files that are watched for reloading.
Type: string
The directory where your package.json
is.
Type: string
The path of the Electron binary used to spawn child processes.
Type: object
Type: boolean
Default: false
Prints watched paths and when files change. Can be useful to make sure you set it up correctly.
Type: Array<string | RegExp>
Ignore patterns passed to chokidar
. By default, files/directories starting with a .
, .map
files, and node_modules
directories are ignored. This option is additive to those.
Type: Array<string>
Args passed to Electron child process when spawned.