hot-module-require
v4.0.3
Published
Detect module's update recursively on nodejs.
Downloads
176
Maintainers
Readme
hot-module-require
Detect module's update recursively on nodejs.
Usage
// module.js
module.exports = require('./foo') + require('./bar')
const makeHotRequire = require('hot-module-require')
const hotRequire = makeHotRequire(__dirname)
let mExports = require('./module')
hotRequire.accept(['./module'], (oldModule, path) => {
// Do something here
// when './module' module or submodules('./foo', './bar'') be detected changed.
let newExports = require('./module')
})
// Or use it like follows
const hotModuleGetter = hotRequire('./module')
hotModuleGetter() // Returns the already updated `require('./module')``
hotModuleGetter.remove() // Calls `remove` for interrupting detect updated
Express Example
npm run example
API
makeHotRequireFunction
- See: More options see detect-dep
make a hot require instance
Parameters
dirname
(optional, default''
)presetOpts
{{}} (optional, default{}
)presetOpts.recursive
{boolean} Analysis file recursively (optional, defaulttrue
)
Returns HotRequire
HotRequire
resolve
Resolve file name
Parameters
name
{string}
watcher
- See: chokidar
file Watcher
emitter
The event emitter
dependent
The map about dependent relations
Type: Map
dependence
The map about dependence relations
Type: Map
getDependenceTree
Get dependence tree of which file
Parameters
modulePath
{string}opts
Returns {}
addDependencies
Add Dependencies
Parameters
modulePath
{string}deps
{string[]}
removeDependencies
Remove Dependencies
Parameters
modulePath
{string}deps
{string[]}
accept
Watch file with callback and make dependence(dependent) relations
Parameters
deps
{string[]}callback
{function}
refuse
Watch file with callback and make dependence(dependent) relations
Parameters
deps
{string[]}callback
{function}
close
Close file watcher
Returns any void
Related
- detect-dep - Detect file's dependencies.