-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Tree shake template literals #3472
Comments
Interestingly, rollup does not support pure annotation before tagged template literals too, related issue here: rollup/rollup#4035 On the other hand, rollup does support /* @__NO_SIDE_EFFECTS__ */
function func(foo) {
console.log(foo)
}
var foo = func`literal` // <-- tree shaked! esbuild currently preserves this magic comment (changelog: 0.18.1), so I guess you can just use this way to write your code. |
You can annotate any arbitrary expression as pure (including template literals) for all tools that support pure annotations (including esbuild and Rollup) by putting it in an IIFE. |
That's not as clean (or performant) as it being implemented in esbuild but that's definitely much better than nothing |
Also it's worth noting that Rollup
|
With the latest release, esbuild will now inline IIFEs that return an expression when minifying, so there should no longer be any performance impact from doing this. |
Open demo
esbuild shouldn't ship
bye
in the bundle, it should only shiphi
.Now I know esbuild can't tell if
t
has side effects. However, while invokingt
withPURE
tree shakes, esbuild still doesn't tree shake the template literal no matter how muchPURE
ing you do.The text was updated successfully, but these errors were encountered: