Skip to content

Instantly share code, notes, and snippets.

@naturecodevoid
Created October 20, 2020 01:40
Show Gist options
  • Save naturecodevoid/a64351bfe324e07888c4fd1d64f4aa88 to your computer and use it in GitHub Desktop.
Save naturecodevoid/a64351bfe324e07888c4fd1d64f4aa88 to your computer and use it in GitHub Desktop.
A simple universal module loader (based on https://github.com/TalAter/annyang/blob/master/dist/annyang.js#L13)
const library = {};
{
if (typeof define === "function" && define.amd) {
// AMD
define([], function () {
return library;
});
}
if (typeof module === "object" && module.exports) {
// CommonJS
module.exports = library;
}
if (typeof global === "object") {
global.library = library;
}
if (typeof window === "object") {
window.library = library;
}
}
// Minified version:
"function"==typeof define&&define.amd&&define([],(function(){return library})),"object"==typeof module&&module.exports&&(module.exports=library),"object"==typeof global&&(global.library=library),"object"==typeof window&&(window.library=library);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment