Skip to content
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

IIFE globalName does not support namespacing via '.' #293

Closed
ggoodman opened this issue Jul 27, 2020 · 4 comments · May be fixed by chncaption/esbuild#3
Closed

IIFE globalName does not support namespacing via '.' #293

ggoodman opened this issue Jul 27, 2020 · 4 comments · May be fixed by chncaption/esbuild#3

Comments

@ggoodman
Copy link

ggoodman commented Jul 27, 2020

When using a namespced globalName invalid javascript is emitted:

esbuild --globalName=A.B --format=iife

Produces the following invalid JavaScript:

var A.B = (() => {
 // ...
})();

The use-case for something like this is supporting suites of related libraries exporting their own exports within a partitioned, common namespace.

I've hacked around this for the time being with:

esbuild --globalName="A = A || {}; A.B" --format=iife
@evanw
Copy link
Owner

evanw commented Jul 28, 2020

Just did a quick survey of other tools. It looks like Rollup is the only tool that supports this. Parcel exports to this["A.B"] instead and Webpack crashes in the minifier with invalid JavaScript.

Parcel's behavior seems the most correct to me. I also found this issue where someone is having problems with the way Rollup does it: rollup/rollup#1473. I'll have to think about what to do here.

@ggoodman
Copy link
Author

It would be neat if the ultimate solution continued to have an escape hatch so that this behaviour remains possible.

@KnisterPeter
Copy link

Webpack does this with something like this config options:

      webpackConfig.output.library = ['A', 'B'];
      webpackConfig.output.libraryTarget = 'umd';

@evanw evanw closed this as completed in 83b307f Oct 28, 2020
@ggoodman
Copy link
Author

🙇 amazing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants