0.10.0 • Published 9 months ago

@hediet/node-reload v0.10.0

Weekly downloads
87
License
MIT
Repository
github
Last release
9 months ago

Hot Reloading for NodeJS

npm.io

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.
0.10.0

9 months ago

0.8.0

2 years ago

0.7.3

6 years ago

0.7.2

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.4.6

6 years ago

0.4.5

6 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago