New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce UMD as a new output format #513
base: main
Are you sure you want to change the base?
Conversation
9337fbf
to
4ea1bc6
Compare
--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
let 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks good to me, though I'd love to see external module support. @prantlf, are you interested in resolving the merge conflicts? If not, I could open a new PR with your changes and the resolution commit.
| @@ -4044,6 +4088,44 @@ func (c *linkerContext) generateGlobalNamePrefix() string { | |||
| return text | |||
| } | |||
|
|
|||
| func generateModuleNameAssignment(options *config.Options) string { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we expand this to the iife format, too?
|
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 ( |
|
Go for it bois |
|
lesss goooo |

Attempts to fix #507.
UMD format is similar to the IIFE format. Just the module wrapper and setting
the global variable differs. For example:
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