๐Ÿ“ฆ hediet / node-reload

An advanced hot reload solution for Node apps. Works very well for developing VSCode extensions and automating websites with puppeteer.

โ˜… 106 stars โ‘‚ 6 forks ๐Ÿ‘ 106 watching โš–๏ธ MIT License
๐Ÿ“ฅ Clone https://github.com/hediet/node-reload.git
HTTPS git clone https://github.com/hediet/node-reload.git
SSH git clone git@github.com:hediet/node-reload.git
CLI gh repo clone hediet/node-reload
Henning Dieterichs Henning Dieterichs update 7797880 11 months ago ๐Ÿ“ History
๐Ÿ“‚ main View all commits โ†’
๐Ÿ“ .vscode
๐Ÿ“ examples
๐Ÿ“ src
๐Ÿ“„ .gitignore
๐Ÿ“„ LICENSE.md
๐Ÿ“„ package.json
๐Ÿ“„ README.md
๐Ÿ“„ tsconfig.json
๐Ÿ“„ yarn.lock
๐Ÿ“„ README.md

Hot Reloading for NodeJS

A thoughtfully designed library that brings advanced hot reloading to NodeJS.

Features

  • Tracks a dependency graph (files in node_modules and there like can be ignored).
  • Tracked files are watched for changes.
  • If a file has changed, reconcilers try to apply the change to the running app on a module basis.
  • If a reconciler is not successful, the reconcilers of the dependees are asked to apply the change.

Usage

Installation

yarn add @hediet/node-reload

or

npm install @hediet/node-reload --save

See the ./examples folder for detailed examples. Works best with TypeScript.

Hot Reload Exported Items

hotReloadExportedItem makes it very easy to track changes of exported items.

import { enableHotReload } from "@hediet/node-reload/node"; // This import needs nodejs.

// Call this before importing modules that should be hot-reloaded!
enableHotReload({
	entryModule: module, // only this module and its transitive dependencies are tracked
	logging: 'debug', // useful for debugging if hot-reload does not work
});

import { hotReloadExportedItem } from "@hediet/node-reload"; // This import is bundler-friendly and works in any environment!
import { myFunction } from './dep1';

const d = hotReloadExportedItem(myFunction, myFunction => {
	// Runs initially and on every change of `myFunction`
    console.log('myFunction: ' + myFunction());
	return {
		dispose: () => {
			console.log('cleanup');
		}
	}
});
// ...
d.dispose();

Similar libs

Changelog

  • 0.0.2 - Initial release.
  • 0.4.2 - Implements Live Debug
  • 0.10.0 - Rewrite. Focus on hotReloadExportedItem and more portable code.