The sideEffects Contract: Tuning Rollup Tree-Shaking for Library Builds
Tree-shaking in Rollup depends on a precise sideEffects contract. Learn how ESM boundaries, named exports, and visualizer audits keep library bundles lean.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Tree-shaking in Rollup depends on a precise sideEffects contract. Learn how ESM boundaries, named exports, and visualizer audits keep library bundles lean.
A practical audit for Rollup bundles: identify exports that survive tree shaking, decide between moduleSideEffects and /*@__PURE__*/ annotations, and verify the result without breaking side-effect code.
Use Vite build.lib to bundle a library entry point, externalize dependencies, and wire up package.json exports for npm consumers.
Spot and fix Rollup tree‑shaking failures that leave unused code in your bundle. Follow a step‑by‑step diagnostic checklist, example config, and verification steps to reduce bundle size.
Learn how Rollup’s static analysis removes unused JavaScript, what configuration and side‑effect markings are required, and how to verify the savings in a real‑world bundle.
Learn how Rollup's preserveModules option keeps your ES module file structure intact while allowing tree‑shaking of external dependencies.
Diagnose Rollup circular dependency warnings by reading the module chain, extracting shared code to a leaf module, deferring with dynamic import, or externalizing third-party cycles.
Learn how Rollup's manualChunks option separates vendor code into a stable chunk, improving long‑term caching and reducing unnecessary downloads.
A decision guide for publishing a library with Rollup: why dual es + cjs output is the practical default, how external and sideEffects settings make or break tree-shaking, and how to validate the result.