Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CommonJS module loader in Firefox

CommonJS module loader in Firefox

Lightning talk at Firefox work week about add-on SDK loader that is planned to land to Firefox soon.

9289db62d5c34afb4f277a5215e05c83?s=128

gozala

May 04, 2012
Tweet

Transcript

  1. CommonJS module loader

  2. Yet another way to load modules

  3. But this time standard modules!

  4. More than 9K of modules were written

  5. let { doStuff } = require('other/libs') exports.stuff = function(options) {

    // do some stuff... } You can require other libs and export your stuff Each module is loaded in it’s own sandbox You can expose stuff by putting it into exports
  6. let { Loader, Require, unload } = Cu.import('resource:///modules/sdk/loader.js') You can

    import loader as JSM
  7. <script src='resource:///modules/sdk/loader.js'></script> As a regular script

  8. let { Loader, Require, unload } = require('loader') Or load

    loader with a loader itself
  9. let loader = Loader({ // provide path for modules baseURI:

    'resource:///modules/', // provide module global bindings globals: { console: { log: dump } }, // provide set of built-in modules modules: { 'dev-tools/gcli': Cu.import('resource:///modules/gcli.jsm'), 'net/utils': Cu.import('resource:///modules/NetUtil.jsm'), } }) Creating a loader is pretty simple
  10. let require = Require(loader, module) require('some-stuff') With a loader you

    can create require, to require stuff
  11. require('browser/places') require('toolkit/auto-complete') require('devtools/scratchpad') exports.Thank = You And hopefully soon enough

    you’ll be able to require any browser component