esbuild
esbuild copied to clipboard
Introduce UMD as a new output format
Attempts to fix #507.
--format=... Output format (iife | cjs | umd | esm, no default
when not bundling, otherwise default is iife when
platform is browser and cjs when platform is node)
UMD format is similar to the IIFE format. Just the module wrapper and setting the global variable differs. For example:
// IIFE
var moduleName = (() => {
... bundled code ...
return exports;
})();
// UMD
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory();
} else {
root.moduleName = factory();
}
}(typeof self !== 'undefined' ? self : this, () => {
... bundled code ...
return exports;
}));
The module contents is generated with the help of the CJS wrapper, like IIFE.
This change supports only building of standalone applications or libraries. All
dependencies have to be included inside the output bundle or loaded by global
variables. Referring to external dependencies using AMD or CJS is not supported. Internal dependencies can be referred to according to input module formats supported by esbuild
Would be super cool to see this merged. Thanks for your work on this PR @prantlf ! 🙇🏽
oh my god, i want this
i want this too
Would be very useful to me too, what is blocking this to get merged?
EDIT: Definitely would like to get this merged, but in the meantime i used babel + babel-plugin-transform-umd as a post-processing phase after esbuild.
EDIT2: In case anyone is interested in how to do that (⚠️ not super clean code ahead, need to refactor/test/document it yet, but it works in a stable way anyway):
Go for it bois
lesss goooo