-
-
Save jrburke/1387943 to your computer and use it in GitHub Desktop.
Common module boilerplate that sets export value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define a module "a" that depends another module called "b". If | |
// that other module also uses this type of boilerplate, then | |
// in the browser, it will create a global .b that is used below. | |
// If you do not want to support the browser global path, then you | |
// can remove the `root` use and the passing `this` as the first arg to | |
// the top function. | |
(function(root, factory) { | |
if (typeof exports === 'object') { | |
// Node. Does not work with strict CommonJS, but | |
// only CommonJS-like enviroments that support module.exports, | |
// like Node. | |
module.exports = factory(require('b')); | |
} else if (typeof define === 'function' && define.amd) { | |
// AMD. Register as an anonymous module. | |
define(['b'], factory); | |
} else { | |
// Browser globals | |
root.a = factory(root.b); | |
} | |
}(this, function(b) { | |
//use b in some fashion. | |
//Just return a value to define the module export. | |
return {}; | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please see the umdjs/umd project for different variations on this kind of boilerplate depending on what you want to support.