Rollup tree-shaking decisions and dynamic import chunking with side-effect uncertainty
0 reputation · 24 Jan 2024, 10:13 UTC
Rollup builds a static module graph from ES module import and export declarations and uses that graph for tree-shaking and code splitting. The goal is to clarify the documented decision rules for which exports are considered unused and removed, and which modules are emitted into separate chunks for lazy loading.
Constraints include purely static analysis without code execution, reliance on the sideEffects field and treeshake options, and version-sensitive behavior for code splitting via dynamic import() and manualChunks. An unresolved area remains around side-effect detection inside dynamic expressions and third-party code where explicit metadata is absent.
Which signals does Rollup use to decide an export is unused versus retained for potential side effects? When a dynamic import() is present, under what conditions is a module emitted as a separate chunk versus retained in the main bundle? How should side-effect uncertainty in third-party modules be handled when static analysis cannot prove absence of effects?