Last active
February 11, 2024 23:02
-
-
Save bttmly/f7172c00fdcd45b9415a to your computer and use it in GitHub Desktop.
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
(function(root, factory) { | |
// Set up Module appropriately for the environment. Start with AMD. | |
if (typeof define === 'function' && define.amd) { | |
define(['underscore', 'exports'], function(_, exports) { | |
// Export global even in AMD case in case this script is loaded with others that may still expect a global "Module". | |
root.Module = factory(root, exports, $); | |
}); | |
// Next for Node.js or CommonJS. | |
} else if (typeof exports !== 'undefined') { | |
var _ = require('underscore'); | |
factory(root, exports, _); | |
//Finally, as a browser global. | |
} else { | |
root.Module = factory(root, {}, root._ ); | |
} | |
}(this, function(root, Module, _, ) { | |
// your library here. | |
return Module; | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Set up a JS project to be environment agnostic. Shamelessly stolen from the beginning of Backbone
This example has Underscore as an example dependency. Use the pattern demonstrated to add any dependencies to your library. "Module" should be replaced with the name of your library's main object.