Last active
December 14, 2015 20:40
-
-
Save wheeyls/5145026 to your computer and use it in GitHub Desktop.
Export a library for commonjs, nodejs, and browser.
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 myLib() { | |
return { | |
code: function () {} | |
, goes: function () {} | |
, here: function () {} | |
} | |
} | |
exporter('myLib', myLib); |
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 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