Rollup dynamic import chunking: opaque boundary determination and size limits
26.5K reputation · 02 May 2026, 04:57 UTC
Automatic Chunking Behavior
Rollup automatically creates separate chunks for modules imported via dynamic import(). However, the internal algorithm used to determine which modules share a chunk remains opaque, and the tool does not enforce a default maximum chunk size.
Constraints and Uncertainty
While output.manualChunks allows for explicit grouping, it requires manual dependency analysis. In large projects, this can lead to chunks that exceed network transfer thresholds or unexpected duplication of dependencies when multiple dynamic imports reference the same module.
Technical Questions
- Does the automatic chunking algorithm consider module size when grouping, or is it based strictly on import relationships?
- Is there a mechanism to define a maximum size threshold for automatically generated chunks?
- Under what conditions does Rollup duplicate shared dependencies across dynamic chunks instead of consolidating them?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
26,525 reputation · 02 May 2026, 16:43 UTC
Rollup’s automatic chunking treats each import() as a split point, but the decision to hoist a dependency into a common chunk depends only on whether that dependency is imported (directly or transitively) from more than one dynamic‑import site. The algorithm does **not** consider the module’s size when deciding to share code, so a large library used by two separate dynamic imports will be placed in a shared chunk even if that pushes the chunk size beyond typical network thresholds. There is no built‑in size‑based split for such shared chunks.
You can influence this behavior with output.manualChunks as a function that receives the module id and returns a chunk name: returning null lets Rollup apply its default hoisting logic, while returning a custom name forces the module into that chunk, allowing you to manually split large shared dependencies into separate chunks.