Skip to content

Lesson 2 of 9 · 20m

esbuild vs Rollup: Why Vite Uses Both

esbuild is the fast compiler and dependency packer; Rollup is the deliberate production linker — Vite deliberately plays to each one's strengths.

The confusing part of Vite is not that it uses two bundlers. It is that people expect one tool to be best at two different jobs. esbuild is a speed machine written in Go; Rollup is a mature JavaScript linker with a plugin ecosystem designed for precise output. Vite uses esbuild where milliseconds dominate the dev loop and Rollup where correctness and artifact shape dominate production.

esbuild: compiler speed as a feature

esbuild parses, transforms, minifies, and bundles with aggressive parallelism. In Vite it handles TypeScript/JSX transforms and dependency pre-bundling:

esbuild src/entry.ts --bundle --outfile=out.js --format=esm --minify

Its superpower is not only “fast”. Fast enough changes behavior: teams stop avoiding recompilation, test runs become bearable, and cold dependency processing stops being coffee-break work.

Rollup: output you can reason about

Rollup's value is deterministic module linking, mature treeshaking, chunk control, and a plugin API that has carried a decade of production builds. A minimal config is honest about input and output:

// rollup.config.js
export default {
  input: "src/entry.js",
  output: {
    dir: "dist",
    format: "esm",
    entryFileNames: "assets/[name]-[hash].js",
  },
};

Rollup is rarely the fastest option, but production builds usually run once per deploy. Paying three extra seconds for predictable chunks is often a bargain.

Why the split leaks into practice

Because dev and production use different engines, behavior can diverge. Classic examples:

  • esbuild supports syntax Rollup does not understand without a plugin.
  • dependency pre-bundling rewrites import "pkg" differently in dev.
  • Rollup treeshaking exposes side-effect assumptions hidden in dev.

This is not an argument against Vite; it is the price of optimizing each phase correctly. Your job is to keep both paths honest through production smoke tests.

Field notes

  • Never debug a production-only import failure only in vite dev; run vite build && vite preview.
  • esbuild does not typecheck TypeScript. It erases types; tsc --noEmit is still a separate CI gate.
  • Rollup warnings like “use of eval is strongly discouraged” often reveal dependencies that defeat static analysis.
  • If a plugin orders transforms differently between dev and build, suspect plugin enforce ordering before blaming Vite core.

Was this lesson helpful?

Sign in to rate