Skip to content

Instantly share code, notes, and snippets.

@wheeyls
Last active December 14, 2015 20:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wheeyls/5145026 to your computer and use it in GitHub Desktop.
Save wheeyls/5145026 to your computer and use it in GitHub Desktop.
Export a library for commonjs, nodejs, and browser.
function myLib() {
return {
code: function () {}
, goes: function () {}
, here: function () {}
}
}
exporter('myLib', myLib);
function exporter(name, definition) {
var old, lib;
// AMD
if (typeof define === 'function') {
define(definition);
// CommonJS
} else if (typeof exports === 'object') {
module.exports = definition();
// Browser
} else {
window[name] = definition();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment