Code Monkey home page Code Monkey logo

hot-module-require's Introduction

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

hot-module-require's People

Contributors

imcuttle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

hot-module-require's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.