Build tools transform, bundle, and optimize your source code for delivery. Vite, Webpack, esbuild, Rollup, and Turbopack each make different trade-offs between dev speed, bundle quality, and ecosystem maturity. Knowing what each one actually does makes you better at configuring them, debugging them, and choosing between them.
esbuild (2020, Evan Wallace) is written in Go and is 10, 100x faster than JavaScript-based tools. It's not primarily a dev server or full build system, it's a transformer and bundler.
Vite (2020, Evan You) is the dev server and build tool that replaced Vue CLI and Create React App as the default for most projects.
Dev mode (the key insight): Vite doesn't bundle in development. It serves files as native ES modules directly to the browser. The browser's module system handles imports. Only the file you changed is reloaded, HMR is near-instant.
Dev server: browser requests /src/App.tsx Vite transforms file on-demand (via esbuild) Returns transformed module No full bundle step
Build mode: Uses Rollup under the hood for production bundling (better tree shaking and code splitting than esbuild's bundler at the time of writing).
Plugin ecosystem: Vite's plugin API is a superset of Rollup's plugin API, most Rollup plugins work in Vite.
Pre-bundling: On first dev server start, Vite uses esbuild to pre-bundle node_modules (CommonJS โ ESM, combine many small files). This is why the first start is slow; subsequent starts use cache.
Webpack (2012) is the oldest and most battle-tested bundler. It builds a dependency graph starting from entry points, applies loaders to transform files, and plugins to process the output.
Loaders transform individual files (TypeScript, CSS, images). Plugins operate on the full bundle graph.
Why Webpack persists despite newer tools:
Mature ecosystem: thousands of plugins
Advanced code splitting control
Module Federation (micro-frontends)
Next.js used it (now migrating to Turbopack)
Large enterprises have complex configs invested in it
Why Webpack is slow: It's JavaScript processing JavaScript. Each file goes through the Node.js loader chain. Large projects see 60, 120 second cold builds. Webpack 5 added persistent caching to mitigate this.
Rollup produces cleaner output than Webpack for libraries, no runtime overhead, no module bootstrapping code. This is why every major library (React, Vue, Lodash) publishes Rollup-built artifacts.
Vite uses Rollup for production builds because Rollup's tree shaking and code splitting produce smaller, more optimised output than esbuild's bundler.
Turbopack (2022, Vercel) is written in Rust and designed as the successor to Webpack inside Next.js. Like esbuild, Rust's performance dwarfs JavaScript.
Key design: incremental computation. Turbopack builds a dependency graph and caches the result of every transformation. On change, only the affected subgraph is recomputed, not the entire bundle. This is similar to build systems like Bazel.
Currently: Turbopack dev server is stable in Next.js 15+ (next dev --turbopack). Production builds are in beta. The goal is to replace Webpack entirely in Next.js.
1. Using ts-loader + babel-loader together in Webpack#
Two TypeScript transforms in series. Use babel-loader with @babel/preset-typescript for fast stripping, and run tsc --noEmit separately for type checking.
2. Not setting contenthash in Webpack output filenames#
Without [contenthash], filenames don't change when content changes. Browsers serve the old cached file. Always use [name].[contenthash].js for long-term caching.
import _ from 'lodash'; // bundles entire lodash (~70KB gzipped)import get from 'lodash/get'; // bundles only get (~4KB)import { get } from 'lodash'; // tree-shakable if ESM lodash-es
Use lodash-es or per-function imports. Verify with a bundle analyzer.
webpack-bundle-analyzer or Vite's rollup-plugin-visualizer shows exactly what's in your bundle. Running this once often reveals 3, 5 quick wins (duplicate deps, huge libraries, unnecessary polyfills).
HMR boundary misconfiguration causes full-page reloads instead of hot updates. In React: @vitejs/plugin-react (Babel) or @vitejs/plugin-react-swc (SWC) handle this. Don't fight the defaults.
esbuild is the fastest transformer. If you're processing TS/JS in scripts or pre-commit hooks, use esbuild API directly.
Vite's optimizeDeps.include: pre-bundle deps that Vite would otherwise discover lazily (reduces waterfall on first dev load).
Webpack persistent cache (cache: { type: 'filesystem' }) in Webpack 5 reduces cold build time from 60s to ~5s on subsequent builds.
Code splitting is the highest-impact production optimization, a single 2MB bundle that loads upfront becomes 5 ร 200KB chunks loaded on demand. Vite does this automatically via dynamic import().
plugins: [
new HtmlWebpackPlugin({ template: './public/index.html' }),
new MiniCssExtractPlugin({ filename: '[name].[contenthash].css' }),
],
optimization: {
splitChunks: { chunks: 'all' },
minimize: true,
},
};
Turbopack
Turborepo
build.sourcemap: true
hidden-source-map
Set build.target to the browsers you actually support, avoids unnecessary polyfill bloat.