Skip to content

Commit cf85c75

Browse files
committed
UMD plugin: export default as module.exports
Fixes babel/babel#17474 (comment)
1 parent c780a90 commit cf85c75

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

esbuild.mjs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,22 @@ const umd = {
5959

6060
build.initialOptions.banner = {
6161
js: `
62-
(function (global, factory, m) {
63-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(module${requireDeps.join(', ')}) :
64-
typeof define === 'function' && define.amd ? define(['module'${amdDeps.join(', ')}], factory) :
65-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(m = { exports: {} }${browserDeps.join(', ')}), global.${browserGlobal} = 'default' in m.exports ? m.exports.default : m.exports);
62+
(function (global, factory) {
63+
if (typeof exports === 'object' && typeof module !== 'undefined') {
64+
factory(module${requireDeps.join(', ')});
65+
module.exports = def(module);
66+
} else if (typeof define === 'function' && define.amd) {
67+
define(['module'${amdDeps.join(', ')}], function(mod) {
68+
factory.apply(this, arguments);
69+
mod.exports = def(mod);
70+
});
71+
} else {
72+
const mod = { exports: {} };
73+
factory(mod${browserDeps.join(', ')});
74+
global = typeof globalThis !== 'undefined' ? globalThis : global || self;
75+
global.${browserGlobal} = def(mod);
76+
}
77+
function def(m) { return 'default' in m.exports ? m.exports.default : m.exports; }
6678
})(this, (function (module${locals.join(', ')}) {
6779
`.trim(),
6880
};

0 commit comments

Comments
 (0)