AMD to UMD converter


umdify is a small JavaScript library for converting modules authored in AMD format to UMD format. It's useful for distributing libraries with wide compatibility in mind. Output UMD is compatible with AMD loaders, CommonJS loaders (like node.js), and (optionally) browser globals.

Inspired by and shares the same "modify as little as possible" philosophy with nodefy.

Using npm:

npm install umdify

Converts contents (a valid AMD JavaScript module) to UMD format. moduleName is only required if you want to support browser globals, and will be the name of the exported window property.

Example (node.js):

var fs = require('fs');
var umdify = require('umdify');
var contents = fs.readFileSync('src/myModule.js', 'utf8');
contents = umdify(contents);
fs.writeFileSync('dist/myModule.js', contents);

Want to do a bulk convert? I won't stand in your way. How about node-glob?

var fs = require('fs');
var path = require('path');
var glob = require('glob');
var umdify = require('umdify');
var files = glob.sync('src/**/*.js');
files.forEach(function(file) {
    var contents = fs.readFileSync(file, 'utf8');
    contents = umdify(contents);
    var dest = path.join('dist', file.replace(/^src\//, ''));
    fs.writeFileSync(dest, contents);

Released under the MIT License.