title: On-demand require()
body: <p>Say I create a library in <code>./libname</code> which contains one main file: <code>main.js</code> and multiple optional library files which are occasionally used with the main object: <code>a.js</code> and <code>b.js</code>. </p>
  
  <p>I create <code>index.js</code> file with the following:</p>
  
  <pre><code>exports.MainClass = require('main.js').MainClass; // shortcut
  exports.a = require('a');
  exports.b = require('b');
  </code></pre>
  
  <p>And now I can use the library as follows:</p>
  
  <pre><code>var lib = require('./libname');
  lib.MainClass;
  lib.a.Something; // Here I need the optional utility object
  lib.b.SomeOtherThing;
  </code></pre>
  
  <p>However, that means, I load 'a.js' and 'b.js' always and not when I really need them.</p>
  
  <p>Sure I can manually load the optional modules with <code>require('./libname/a.js')</code>, but then I lose the pretty <code>lib.a</code> dot-notation :)</p>
  
  <p>Is there a way to implement on-demand loading with some kind of index file? Maybe, some <code>package.json</code> magic can play here well?</p>