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
Option to assign default export to globalName for iife format #3740
Comments
To achieve something similar to what you're asking for, I'm using esbuild to generate the ESM bundle, then feeding it to rollup to produce other formats like CJS and IIFE (which will reduce some code of preserving ESM bindings semantics). |
Yeah, i would really want to avoid having to involve another bundler... // proxy.cjs
import awesomeFunction from "foo.js";
module.exports = awesomeFunction;
// bundle.js
await esbuild.build({
entryPoints: ['proxy.cjs'],
bundle: true,
minify: true,
format: "iife",
target: "esnext",
globalName: "awesomeFunction",
outfile: 'foo.min.js'
})
|
...or, this is even possible without the proxy.cjs. await esbuild.build({
stdin: {
contents: 'import a from "./foo.js";module.exports = a;',
resolveDir: '.'
},
bundle: true,
minify: true,
sourcemap: false,
format: "iife",
target: "esnext",
globalName: "awesomeFunction",
outfile: 'foo.min.js'
}) |
in the browser
window.awesomeFunction
is the object{__esModule: true}
, where aswindow.awesomeFunction.default
is the actual function.I understand why this is the case, but the solution from when the issue was mention earlier was to change the exported function type to
module.exports
. But wouldn't it be nicer/more convienient if there was an option in the builder to assign the default export directly to the globalName?...Or, is there a way to do this already, without having to change the import
Extending on this... Maybe an option for using the name of the function (if it has been named) from the import as the
globalName
The text was updated successfully, but these errors were encountered: