Fork me on GitHub


UMD template deployment options


  • There is no additional dependency when 'UMD' moduless are running on Web (AMD/RequireJS) - use them as you would use strict AMD modules. Naturally your UMDs can work seamlessly with other 'native' AMD modules.

  • If you want to optimize your modules and bundle them by hand using r.js or almond etc, you can convert your modules to AMD instead of UMD, and pass them through r.js as you would normally do. uRequire does this in one step via the combined template.


  • On nodejs, as long as 'urequire' package is installed via npm, your UMD generated modules can be used as-is by any UMD or native nodejs module via the bare require('') call. Although your source modules were written in AMD and perhaps use asynchronous require calls, plugins etc they work seamlessly on nodejs.

  • Additionally your ex-AMD/nodejs, now UMDfied modules, can require('module') any node-native module installed via npm or residing on your file system. Its MAD, but RequireJS AMD modules wont let you do that (@version 2.1.1). Note: you have to conditionally make sure the node-natives aren't called/executing on browser; or better replace them with some client counterpart lib! If you want to require('') a node-only module, that shouldn't be added to the deps array, use the node!moduleName pseudo-plugin, that signals node-only execution.

  • You can use native RequireJS loader plugins (eg text!mytext.txt), through RequireJS it self. Your nodejs-looking modules can actually use RequireJS plugins.

  • Finally from within your UMD module you can require native AMD modules on node (ones that aren't converted to UMD, i.e start with define()). If uRequire fails to load a module with node's require, it passes it to RequireJS/node it self - this perhaps needs more testing, but it does the trick for now.

Plain UMD

With version >= 0.6.4 you can use 'UMDplain' template, which has no dependency on 'urequire' on nodejs but you 'll be missing all of the above goodies - i.e no AMD plugins, no native AMD requires, no path resolution, no mappings and more - check nodejs template for limitations.

Deployment options for combined template

The combined template builds your bundle as a single .js file, ready to be deployed in any environment:

Web/Script </script>

Works in browser, as a simple <script/>, independently of AMD/RequireJS. The script can register some global (window) variables when it loads, for example $2 or _B, via the rootExports declaration.

It accesses all other (non-inlined) global dependencies (eg 'underscore') through the global space (window), like all plain <script/> do. So for example, you <script/> load your 'jquery.js', 'lodash.js' and 'Backbone.js' and then you load your 'MyUrequireCombinedApp.js' and you're done!


The combined script works as a normal AMD dependency, loading all other (non-included) dependencies through AMD's mechanism. In other words its using rjs.baseUrl, rjs.paths, rjs.shim etc.


Works in nodejs, as is. Its loading all (non-inlined) dependencies through nodejs's 'require()'.

It has no other dependencies, i.e you dont need to have uRequire or RequireJs installed locally at all.