Skip to content

Repository files navigation

hot-module-require

NPM versionNPM Downloads

Detect module's update recursively on nodejs.

Usage

// module.jsmodule.exports=require('./foo')+require('./bar')
constmakeHotRequire=require('hot-module-require')consthotRequire=makeHotRequire(__dirname)letmExports=require('./module')hotRequire.accept(['./module'],(oldModule,path)=>{// Do something here // when './module' module or submodules('./foo', './bar'') be detected changed.letnewExports=require('./module')})// Or use it like followsconsthotModuleGetter=hotRequire('./module')hotModuleGetter()// Returns the already updated `require('./module')``hotModuleGetter.remove()// Calls `remove` for interrupting detect updated 
npm run example

API

makeHotRequireFunction

index.js:52-373

make a hot require instance

Parameters

  • dirname (optional, default '')
  • presetOpts {{}} (optional, default {})
    • presetOpts.recursive {boolean} Analysis file recursively (optional, default true)

Returns HotRequire

HotRequire

index.js:173-184

resolve

index.js:256-256

Resolve file name

Parameters

  • name {string}

watcher

index.js:263-263

file Watcher

emitter

index.js:269-269

The event emitter

dependent

index.js:276-276

The map about dependent relations

Type: Map

dependence

index.js:283-283

The map about dependence relations

Type: Map

getDependenceTree

index.js:293-293

Get dependence tree of which file

Parameters

  • modulePath {string}
  • opts

Returns {}

addDependencies

index.js:303-303

Add Dependencies

Parameters

  • modulePath {string}
  • deps {string[]}

removeDependencies

index.js:311-311

Remove Dependencies

Parameters

  • modulePath {string}
  • deps {string[]}

accept

index.js:320-331

Watch file with callback and make dependence(dependent) relations

Parameters

  • deps {string[]}
  • callback {function}

refuse

index.js:339-361

Watch file with callback and make dependence(dependent) relations

Parameters

  • deps {string[]}
  • callback {function}

close

index.js:368-370

Close file watcher

Returns any void

Related

About

Hot modules require like HMR(webpack)

Topics

Resources

Stars

12 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages