Last active
February 11, 2024 22:42
-
-
Save cowboy/5779604 to your computer and use it in GitHub Desktop.
The "UMD returnExportsGlobal shuffle"
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
// Re. https://github.com/umdjs/umd/blob/master/returnExportsGlobal.js | |
// ================================================== | |
// Q. Does all that UMD stuff need to be at the top? | |
// ================================================== | |
(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'], function (b) { | |
return (root.returnExportsGlobal = factory(b)); | |
}); | |
} else { | |
// Browser globals | |
root.returnExportsGlobal = factory(root.b); | |
} | |
}(this, function (b) { | |
//use b in some fashion. | |
// Just return a value to define the module export. | |
// This example returns an object, but the module | |
// can return a function as the exported value. | |
return {}; | |
})); | |
// ================================================== | |
// A. Not really. | |
// ================================================== | |
(function (factory, umd, root) { | |
umd(root, factory); | |
}(function (b) { | |
//use b in some fashion. | |
// Just return a value to define the module export. | |
// This example returns an object, but the module | |
// can return a function as the exported value. | |
return {}; | |
}, 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'], function (b) { | |
return (root.returnExportsGlobal = factory(b)); | |
}); | |
} else { | |
// Browser globals | |
root.returnExportsGlobal = factory(root.b); | |
} | |
}, this)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I see what you did there....nice.