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

Treeshaking multiple entry modules with multiple re-exports creates extra chunks (follow-up) #5007

Open
tmsns opened this issue May 22, 2023 · 2 comments

Comments

@tmsns
Copy link

tmsns commented May 22, 2023

Rollup Version

3.23.0

Operating System (or Browser)

Chrome 113

Node Version (if applicable)

N/A

Link To Reproduction

https://rollupjs.org/repl/?version=3.23.0&shareable=JTdCJTIyZXhhbXBsZSUyMiUzQW51bGwlMkMlMjJtb2R1bGVzJTIyJTNBJTVCJTdCJTIyY29kZSUyMiUzQSUyMmltcG9ydCUyMCU3QiUyMGRvdWJsZSUyMCU3RCUyMGZyb20lMjAnLiUyRm1hdGguanMnJTNCJTVDbiU1Q25jb25zb2xlLmxvZyhkb3VibGUoNSkpJTNCJTIyJTJDJTIyaXNFbnRyeSUyMiUzQXRydWUlMkMlMjJuYW1lJTIyJTNBJTIybWFpbi5qcyUyMiU3RCUyQyU3QiUyMmNvZGUlMjIlM0ElMjJleHBvcnQlMjAlN0IlMjBkb3VibGUlMjAlN0QlMjBmcm9tJTIwJy4lMkZtYXRoJTJGbXVsdGlwbGljYXRpb24uanMnJTNCJTVDbmV4cG9ydCUyMCU3QiUyMHN1bSUyMCU3RCUyMGZyb20lMjAnLiUyRm1hdGglMkZhZGRpdGlvbi5qcyclM0IlMjIlMkMlMjJpc0VudHJ5JTIyJTNBdHJ1ZSUyQyUyMm5hbWUlMjIlM0ElMjJtYXRoLmpzJTIyJTdEJTJDJTdCJTIyY29kZSUyMiUzQSUyMmV4cG9ydCUyMGNvbnN0JTIwZG91YmxlJTIwJTNEJTIweCUyMCUzRCUzRSUyMHglMjAqJTIwMiUzQiUyMiUyQyUyMmlzRW50cnklMjIlM0FmYWxzZSUyQyUyMm5hbWUlMjIlM0ElMjJtYXRoJTJGbXVsdGlwbGljYXRpb24uanMlMjIlN0QlMkMlN0IlMjJjb2RlJTIyJTNBJTIyZXhwb3J0JTIwY29uc3QlMjBzdW0lMjAlM0QlMjAoeCUyQyUyMHkpJTIwJTNEJTNFJTIweCUyMCUyQiUyMHklM0IlMjIlMkMlMjJpc0VudHJ5JTIyJTNBZmFsc2UlMkMlMjJuYW1lJTIyJTNBJTIybWF0aCUyRmFkZGl0aW9uLmpzJTIyJTdEJTVEJTJDJTIyb3B0aW9ucyUyMiUzQSU3QiUyMm91dHB1dCUyMiUzQSU3QiUyMmZvcm1hdCUyMiUzQSUyMmVzJTIyJTdEJTJDJTIydHJlZXNoYWtlJTIyJTNBdHJ1ZSU3RCU3RA==

Expected Behaviour

We expect an output of 2 chunks (main.js & math.js) where the internal used module math/multiplication.js is bundled into math.js

Actual Behaviour

When treeshaking is active, Rollup creates an extra chunk for the used internal module (math/multiplication.js) and references this chunk instead of the originally referenced module (math.js)

This is a follow-up bug on issue #4962. The difference here is that math.js contains a second re-export from another file (math/addition.js) When commenting out this sum re-export (or disabling treeshaking) we have the expected behaviour.

@lukastaegert
Copy link
Member

This one is a little more subtle and I will probably not fix it for reasons I will explain. What Rollup is doing here is that it is trying to minimize the amount of JavaScript loaded per entry (not counting imports and exports).

In your example main.js may import double from math.js, but it actually imports it from another chunk and it does not need square, which is also declared in math.js.

In the output generated by Rollup, loading main.js will not load square. If you add a side effect to math.js, Rollup also needs to include that file with main.js and inadvertently includes square because it cannot split files (yet).

So this is a slightly failed attempt to reduce size, but it can actually have quite some effects if the declarations were more involved. In your example, I would try to set experimentalMinChunkSize to a small value until the unnecessary chunk is merged away.

https://rollupjs.org/repl/?version=3.23.0&shareable=JTdCJTIyZXhhbXBsZSUyMiUzQW51bGwlMkMlMjJtb2R1bGVzJTIyJTNBJTVCJTdCJTIyY29kZSUyMiUzQSUyMmltcG9ydCUyMCU3QiUyMGRvdWJsZSUyMCU3RCUyMGZyb20lMjAnLiUyRm1hdGguanMnJTNCJTVDbiU1Q25jb25zb2xlLmxvZyhkb3VibGUoNSkpJTNCJTIyJTJDJTIyaXNFbnRyeSUyMiUzQXRydWUlMkMlMjJuYW1lJTIyJTNBJTIybWFpbi5qcyUyMiU3RCUyQyU3QiUyMmNvZGUlMjIlM0ElMjJleHBvcnQlMjAlN0IlMjBkb3VibGUlMjAlN0QlMjBmcm9tJTIwJy4lMkZtYXRoJTJGbXVsdGlwbGljYXRpb24uanMnJTNCJTVDbmV4cG9ydCUyMGNvbnN0JTIwc3F1YXJlJTIwJTNEJTIweCUyMCUzRCUzRSUyMHglMjAqJTIweCUzQiU1Q24lMjIlMkMlMjJpc0VudHJ5JTIyJTNBdHJ1ZSUyQyUyMm5hbWUlMjIlM0ElMjJtYXRoLmpzJTIyJTdEJTJDJTdCJTIyY29kZSUyMiUzQSUyMmV4cG9ydCUyMGNvbnN0JTIwZG91YmxlJTIwJTNEJTIweCUyMCUzRCUzRSUyMHglMjAqJTIwMiUzQiUyMiUyQyUyMmlzRW50cnklMjIlM0FmYWxzZSUyQyUyMm5hbWUlMjIlM0ElMjJtYXRoJTJGbXVsdGlwbGljYXRpb24uanMlMjIlN0QlNUQlMkMlMjJvcHRpb25zJTIyJTNBJTdCJTIyb3V0cHV0JTIyJTNBJTdCJTIyZXhwZXJpbWVudGFsTWluQ2h1bmtTaXplJTIyJTNBMTAwJTJDJTIyZm9ybWF0JTIyJTNBJTIyZXMlMjIlN0QlN0QlN0Q=

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

No branches or pull requests

2 participants