Fork me on GitHub

Universal Module Format

With uRequire, your modules can be either written in AMD:

// standard anonymous module format
define(['dep1', 'dep2'], function(dep1, dep2) {
   // do stuff with dep1, dep2
   return {my:'module'}
});

// or a named module
define('moduleName', ['dep1', 'dep2'], function(dep1, dep2) {...});

// or a module without *array* dependencies
define(function() {...})

or in the CommonJs/nodejs format:

var dep1 = require('dep1');
var dep2 = require('dep2');

// do stuff with dep1, dep2
module.exports = {my: 'module'}

or a relaxed* combination of both:

// uRequire relaxed notation
define(['dep1', 'dep2'], function(dep1, dep2) {
   var dep3 = require('dep3');
   // do stuff with dep1, dep2, dep3
   return {my:'module'}
});
  • relaxed means you dont need to be strict to either standard, but also it would NOT work as a plain AMD/nodejs module without uRequire conversion.

uRequire guarantees that your modules are correctly translated and execute on both target environments, even though the easier, less verbose and relaxed format is used.

The idiosyncrasies and limitations of module formats are waived, so you can focus on what is important: you modular code that can be expressed in the easiest sensible way possible.

For instance you can use both the syntax of synchronous & asynchronous require, mix absolute/bundleRelative with fileRelative paths, forget about requiring require or module/exports and just be sure that your code will execute on both runtimes in a consistent way.

Future

In the future other modules formats like ES6 harmony:modules can be used as source or target. But that is only a tiny point of future directions of uRequire.