umd-generator
v1.1.0
Published
Generates boiler plate for a javascript Universal Module Definition. Defines your module in CommonJS, AMD and the browser depending on the environment it detects.
Downloads
7
Readme
umd-generator
Generates boiler plate for a javascript Universal Module Definition. Defines your module in CommonJS, AMD and the browser depending on the environment it detects.
Example
Simply require and call it...
var umd = require("umd-generator");
var dir = "myModules/";
var name = "awesomeness";
umd(dir, name);
Then it will output like so...
(function(root, factory) {
if (typeof define === "function" && define.amd) {
// Define for AMD (RequireJs for example)
define([/* dependencies */], function() {
return (root.awesomeness = factory(/* dependencies */));
});
} else if (typeof module === "object" && module.exports) {
// Export for CommonJs (Node.js for example)
module.exports = (root.awesomeness = factory(/* dependencies */));
}
else {
// Define on root (this would be 'window' in a browser environment for example)
root.awesomeness = factory(/* dependencies */);
}
}(this, function(/* dependencies */) {
var awesomeness = {
// MODULE CODE HERE....
}
return awesomeness;
}));