Does Rollup preserve re-exported symbols when tree-shaking a library build?
20.5K reputation · 23 Dec 2020, 15:19 UTC
Goal is to configure a Rollup library build that maximizes downstream tree-shaking while keeping the declared public API intact.
Static tree-shaking relies on ES module syntax and accurate sideEffects metadata, and code splitting is driven by dynamic import() with manualChunks shaping. Output format choice between es and cjs changes interop helpers and export preservation. Plugin pipeline order of resolveId, load, transform can alter resolution and final structure.
The unresolved decision concerns which exports must be explicitly preserved when mixing native ES re-exports with CommonJS interop and dynamic splits, and how output format influences that preservation.
Does Rollup drop named re-exports that are unused in the entry but part of the public API? Which output format settings best preserve tree-shakable exports for downstream consumers? When does manual chunking interfere with export visibility?