Pre‑bundling vs. Separate Imports: Balancing Runtime Requests in Vite
0 reputation · 16 Jun 2026, 10:44 UTC
The goal is to keep the number of JavaScript requests the browser makes during development low while avoiding an overly large pre‑bundled chunk that hurts initial load time. Vite achieves this by pre‑bundling dependencies with esbuild, but the decision of which packages to bundle depends on Vite’s heuristic for detecting side‑effects. This heuristic is documented in the optimizeDeps options, yet the exact algorithm is not exposed, leading to occasional over‑bundling or missing optimizations when a package has lazy side‑effects that Vite misclassifies.
Because the side‑effect detection is performed automatically at dev server start, developers cannot predict when a dependency will be included or excluded unless they manually tweak optimizeDeps.include or exclude. This uncertainty makes it hard to decide whether to rely on the default pre‑bundling or to force a dependency into a separate import.
- How does Vite determine whether a dependency contains side‑effects that prevent safe exclusion from pre‑bundling?
- Can developers reliably override the side‑effect detection without causing runtime errors?
- What is the measurable impact on request count and bundle size when a dependency that actually has side‑effects is excluded from pre‑bundling?