0.1.4 • Published 5 years ago

electron-hot-reload v0.1.4

Weekly downloads
13
License
MIT
Repository
github
Last release
5 years ago

ElectronJS Hot Reload

npm bundlephobia min bundlephobia minzip

It is a simple method to restart your application.

Features:

  • Separate watchers in main and renderer processes.
  • No magic, you necessary specify path files.
  • You can use hooks before reload.
  • Will catch error, if you want.

Example

First, you should install this package:

# Yarn
yarn add electron-hot-reload

# NPM
npm install --save electron-hot-reload

Next, you should create watchers:

import { mainReloader, rendererReloader } from 'electron-hot-reload';
import { app } from 'electron';
import path from 'path';

const mainFile = path.join(app.getAppPath(), 'dist', 'main.js');
const rendererFile = path.join(app.getAppPath(), 'dist', 'renderer.js');

mainReloader(mainFile, undefined, (error, path) => {
  console.log("It is a main's process hook!");
});

rendererReloader(rendererFile, undefined, (error, path) => {
  console.log("It is a renderer's process hook!");
});

Do you want to example application?

Documentation

mainReloader( paths, ignored, handler, options ) => void

If this is method detects changes, it will restart the application.

ArgumentTypeRequeredDescription
pathsstring or string[]truePaths to files and dirs to recursively watch.
ignoredRegExp or RegExp[]falseRegExp to file or dirs to ignore.
handlerfunctionfalseCallback function to create hooks.
optionsobjectfalseAdditional options to chokidar.

rendererReloader( paths, ignored, handler, options ) => void

If this is method detects changes, it will restart the application's windows.

ArgumentTypeRequeredDescription
pathsstring or string[]truePaths to files and dirs to recursively watch.
ignoredRegExp or RegExp[]falseRegExp to file or dirs to ignore.
handlerfunctionfalseCallback function to create hooks.
optionsobjectfalseAdditional options to chokidar.

License

MIT. Copyright (c) Valentin Popov.