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 #1331
base: main
Are you sure you want to change the base?
Conversation
--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.
|
Definitely having no UMD support breaks legacy projects on some users, so much thanks @gwuhaolin for your effort on this dutie! cc: @jridgewell |
|
For the record, you can achieve this in a hacky way by using the (function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory();
} else {
root.YourExportedModuleAsIIFE = factory();
}
}(typeof self !== 'undefined' ? self : this, () => YourExportedModuleAsIIFE));Of course, it would be better to having UMD support without having to worry about this nuance. |
|
rebase and try to push this request to master @gwuhaolin by the way thanks a lot |
|
I would like to see this merged |
|
agreed! merge ETA? |
|
This is the only feature preventing me from switching from Rollup to ESBuild as the author of 50+ open source JS libraries. Gently bringing this to your attention @evanw 🙏 |
|
really would like this to be added |
|
@gwuhaolin does this PR supports externals ? for example https://github.com/mistic100/Photo-Sphere-Viewer/blob/master/dist/photo-sphere-viewer.js#L7-L11 (this is rollup.js output) edit : well.... as currently a plugin is required to have external globals (esbuild-plugin-external-global), it may not work out of the box. Or said plugin will have to be merged in the core. |
|
why is this pull request still open? |
cherry-pick from #513 with conflicts resolved