1.0.3 • Published 6 years ago
import-reload v1.0.3
IMPORT-RELOAD
Module reloading for Node.js
import-reload is a NPM module that lets you live-relaod modules when they are modified without requiring server restart.
INSTALL
$ npm install import-reloadUSAGE
Example
// foo.ts
export const foo = { bar: 1 };// main.ts
import { reload } from "import-reload";
const foo = await reload(
() => import("./foo"),
Foo => Foo.foo
);
console.log(foo.bar); // outputs 1Then modify foo.ts:
// foo.ts
export const foo = { bar: 2 };Back in main:
console.log(foo.bar); // outputs 2API
reload<U, T extends object>(importFn: () => Promise<U>, extractFn: (module: U) => T): Promise<T>;importFn should use the dynamic import function, e.g. () => import("./module).
extractFn takes in the module returned by the import and returns the object to be used by the program.