Necessary Pigeonholing Mechanism
    Have ideas to improve npm?Join in the discussion! »

    hot-module-require

    4.0.0 • Public • Published

    hot-module-require

    NPM version NPM Downloads

    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 

    API

    makeHotRequireFunction

    index.js:52-372

    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:172-185

    resolve

    index.js:255-255

    Resolve file name

    Parameters

    • name {string}

    watcher

    index.js:262-262

    file Watcher

    emitter

    index.js:268-268

    The event emitter

    dependent

    index.js:275-275

    The map about dependent relations

    Type: Map

    dependence

    index.js:282-282

    The map about dependence relations

    Type: Map

    getDependenceTree

    index.js:292-292

    Get dependence tree of which file

    Parameters

    • modulePath {string}
    • opts

    Returns {}

    addDependencies

    index.js:302-302

    Add Dependencies

    Parameters

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

    removeDependencies

    index.js:310-310

    Remove Dependencies

    Parameters

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

    accept

    index.js:319-330

    Watch file with callback and make dependence(dependent) relations

    Parameters

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

    refuse

    index.js:338-360

    Watch file with callback and make dependence(dependent) relations

    Parameters

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

    close

    index.js:367-369

    Close file watcher

    Returns any void

    Related

    Install

    npm i hot-module-require

    DownloadsWeekly Downloads

    61

    Version

    4.0.0

    License

    MIT

    Unpacked Size

    28.4 kB

    Total Files

    28

    Last publish

    Collaborators

    • avatar