deferred-require

0.4.0 • Public • Published

Deferred Require

Using this module requires that you run node with the --harmony_proxies and --harmony_collections flags.

deferredRequire = require 'deferred-require'
myHugeModule = require 'my-huge-module'
 
# ... some time later ... 
 
myHugeModule.doSomething() # the module isn't loaded and required until here 

This npm exports a single top-level function, deferredRequire, which you can use just as you would use node's global require function. When you require a module with deferredRequire, no code is actually loaded or evaluated until the module you require is first used. This is achieved through the magic of harmony proxies.

Warning: Because of instability in the v8 proxy implementation when combined with "exotic objects" like arrays, strings, and dates, you should only use deferredRequire with modules that export regular objects or functions as their top-level module. This is true of almost every npm module, so in practice this shouldn't be a big issue.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.4.0
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.4.0
    1
  • 0.3.0
    0
  • 0.2.0
    0
  • 0.1.0
    0

Package Sidebar

Install

npm i deferred-require

Weekly Downloads

1

Version

0.4.0

License

none

Last publish

Collaborators

  • atom-team
  • nathansobo
  • kevinsawicki
  • probablycorey