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 cross-referencing creates extra chunks #4962
Comments
Some more background info: Possible CauseWe think that Rollup tries to optimize the output bundle and as he notices a module ( We tried to change the behavior using some of the options of Rollup, but none of them ( WorkaroundsAs we were surprised by this result, we tried to workaround this behavior. We came up with a number of ways, none of which are ideal.
import { basename } from 'path';
/**
* Bundles all first level imports of an entry module together with its entry in the same chunk.
*
* @type {import('rollup').GetManualChunk}
*/
export function bundleImportsOfEntries(id, { getModuleInfo }) {
const moduleInfo = getModuleInfo(id);
if (moduleInfo.isEntry) {
return basename(id);
}
const entryPoint = moduleInfo.importers.find(importer => getModuleInfo(importer).isEntry);
if (entryPoint) {
return basename(entryPoint);
}
return undefined;
} |
This issue has been resolved via #4989 as part of rollup@3.22.0-0. Note that this is a pre-release, so to test it, you need to install Rollup via |
This issue has been resolved via #4989 as part of rollup@3.22.0. You can test it via |
Rollup Version
3.21.0
Operating System (or Browser)
Chrome 112
Node Version (if applicable)
N/A
Link To Reproduction
https://rollupjs.org/repl/?version=3.21.0&shareable=JTdCJTIyZXhhbXBsZSUyMiUzQW51bGwlMkMlMjJtb2R1bGVzJTIyJTNBJTVCJTdCJTIyY29kZSUyMiUzQSUyMmltcG9ydCUyMCU3QiUyMGRvdWJsZSUyMCU3RCUyMGZyb20lMjAnLiUyRm1hdGguanMnJTNCJTVDbiU1Q25jb25zb2xlLmxvZyhkb3VibGUoNSkpJTNCJTIyJTJDJTIyaXNFbnRyeSUyMiUzQXRydWUlMkMlMjJuYW1lJTIyJTNBJTIybWFpbi5qcyUyMiU3RCUyQyU3QiUyMmNvZGUlMjIlM0ElMjJleHBvcnQlMjAlN0IlMjBkb3VibGUlMjAlN0QlMjBmcm9tJTIwJy4lMkZpbnRlZ2VyLW1hdGguanMnJTNCJTIyJTJDJTIyaXNFbnRyeSUyMiUzQXRydWUlMkMlMjJuYW1lJTIyJTNBJTIybWF0aC5qcyUyMiU3RCUyQyU3QiUyMmNvZGUlMjIlM0ElMjJleHBvcnQlMjBjb25zdCUyMGRvdWJsZSUyMCUzRCUyMHglMjAlM0QlM0UlMjB4JTIwKiUyMDIlM0IlMjIlMkMlMjJpc0VudHJ5JTIyJTNBZmFsc2UlMkMlMjJuYW1lJTIyJTNBJTIyaW50ZWdlci1tYXRoLmpzJTIyJTdEJTVEJTJDJTIyb3B0aW9ucyUyMiUzQSU3QiUyMm91dHB1dCUyMiUzQSU3QiUyMmZvcm1hdCUyMiUzQSUyMmVzJTIyJTdEJTJDJTIydHJlZXNoYWtlJTIyJTNBdHJ1ZSU3RCU3RA==
Expected Behaviour
We expect an output of 2 chunks where the internal used module
integer-math.js
is bundled intomath.js
Actual Behaviour
When treeshaking is active, Rollup creates an extra chunk for the internal module (
integer-math.js
) and references this chunk instead of the originally referenced module (math.js
)The text was updated successfully, but these errors were encountered: