Skip to content

Instantly share code, notes, and snippets.

@oscarotero
Created May 22, 2016 11:25
Show Gist options
  • Save oscarotero/a0c17f381dce7bf77b0be4a59f451f4f to your computer and use it in GitHub Desktop.
Save oscarotero/a0c17f381dce7bf77b0be4a59f451f4f to your computer and use it in GitHub Desktop.
Boilerplate to create amd/cmjs/root js modules
(function (root, factory) {
if(typeof define === "function" && define.amd) {
// Now we're wrapping the factory and assigning the return
// value to the root (window) and returning it as well to
// the AMD loader.
define(["postal"], function(postal){
return (root.myModule = factory(postal));
});
} else if(typeof module === "object" && module.exports) {
// I've not encountered a need for this yet, since I haven't
// run into a scenario where plain modules depend on CommonJS
// *and* I happen to be loading in a CJS browser environment
// but I'm including it for the sake of being thorough
module.exports = (root.myModule = factory(require("postal")));
} else {
root.myModule = factory(root.postal);
}
}(this, function(postal) {
// module code here....
return myModule;
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment