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

esbuild does not tree shake known globals #842

Closed
moos opened this issue Feb 18, 2021 · 3 comments
Closed

esbuild does not tree shake known globals #842

moos opened this issue Feb 18, 2021 · 3 comments

Comments

@moos
Copy link

moos commented Feb 18, 2021

esbuild:

$ echo "class A extends HTMLElement {}" | npx esbuild --bundle --format=esm
// <stdin>
var A = class extends HTMLElement {
};

Rollup:

$ echo "class A extends HTMLElement {}" | npx rollup
- → stdout...
(!) Generated an empty chunk
-

For unknown globals (e.g., "class A extends Foo {}"), both esbuild and rollup keep the definition.

It would be great if esbuild could also filter for known globals.

Related:

@evanw
Copy link
Owner

evanw commented Feb 19, 2021

There is limited support for this already in esbuild here:

var knownGlobals = [][]string{
// These global identifiers should exist in all JavaScript environments
{"Array"},
{"Boolean"},
{"Function"},
{"Math"},
{"Number"},
{"Object"},
{"RegExp"},
{"String"},

This does not yet encode DOM globals, however.

@moos
Copy link
Author

moos commented Feb 19, 2021

Ah good to know. I'm not a Go programmer but willing to give it a "go" if you want some help. Let me know.

@evanw
Copy link
Owner

evanw commented Feb 19, 2021

It's ok, this is easy for me. I've got this one.

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.

2 participants