{ ILoveJS }

esbuild

Build Tools

An extremely fast bundler for the web

weekly downloads105.3M
versionv0.27.3
licenseMIT
Written in Go10-100x faster than JS bundlersUsed inside Vite

Overview

esbuild is a JavaScript bundler and minifier written in Go that achieves 10-100x faster build times compared to traditional JavaScript-based bundlers. It handles bundling, transpilation, minification, and source map generation in a single tool without requiring complex configuration or caching strategies to achieve its speed. With over 105 million weekly downloads, it has become a foundational tool in the modern JavaScript ecosystem.

The bundler natively supports TypeScript, JSX, CSS, and JSON imports out of the box, automatically stripping types and transforming syntax without requiring separate loaders or plugins. It can target specific browser versions or Node.js environments, adjusting output syntax accordingly while maintaining compatibility. esbuild's architecture leverages Go's parallelism and efficient memory usage to process thousands of modules in milliseconds.

Originally created by Evan Wallace in 2020, esbuild has been adopted by major frameworks and build tools including Vite, SvelteKit, and Remix as their underlying bundler. It's designed for both development (with watch mode and serve capabilities) and production builds, offering tree shaking, code splitting, and multiple output formats (ESM, CommonJS, IIFE). While it lacks some advanced features of mature bundlers, its speed and simplicity make it ideal for modern JavaScript projects that prioritize fast iteration cycles.

Developers choose esbuild when build performance is critical, particularly in large monorepos or projects with frequent rebuilds during development. Its JavaScript and Go APIs provide programmatic access, while the CLI offers quick one-off bundling. The tool's philosophy emphasizes speed and built-in functionality over extensibility, though it does support a plugin system for custom transformations.

Quick Start

typescript
import * as esbuild from 'esbuild';

// Build for production with code splitting
const result = await esbuild.build({
  entryPoints: ['src/index.ts', 'src/admin.ts'],
  bundle: true,
  minify: true,
  sourcemap: true,
  splitting: true,
  format: 'esm',
  target: ['chrome90', 'firefox88', 'safari14'],
  outdir: 'dist',
  loader: {
    '.png': 'dataurl',
    '.svg': 'file'
  },
  define: {
    'process.env.NODE_ENV': '"production"',
    '__VERSION__': '"1.0.0"'
  },
  metafile: true
});

// Analyze bundle size
const analysis = await esbuild.analyzeMetafile(result.metafile, {
  verbose: true
});
console.log(analysis);

// Development server with watch mode
const ctx = await esbuild.context({
  entryPoints: ['src/index.ts'],
  bundle: true,
  outdir: 'dist',
  sourcemap: 'inline',
  format: 'esm'
});

await ctx.watch();
await ctx.serve({
  servedir: 'dist',
  port: 3000
});

console.log('Dev server running at http://localhost:3000');

Use Cases

Production bundling for web applications: Bundle and minify JavaScript, TypeScript, and CSS for deployment, with automatic tree shaking to eliminate unused code. esbuild generates optimized outputs with source maps in a fraction of the time traditional bundlers require.

Development server with hot reload: Use esbuild's serve mode to run a development server that bundles on-demand from memory, combined with watch mode to rebuild instantly when files change. This provides near-instantaneous feedback during development.

TypeScript compilation without tsc: Strip TypeScript types and transform JSX/TSX files directly for Node.js applications or libraries. esbuild handles syntax transformation without type checking, making it ideal for build pipelines where type checking runs separately.

Build tool foundation: Integrate esbuild as the bundling engine within meta-frameworks or custom build tools, as Vite does. Its programmatic API allows fine-grained control while maintaining exceptional performance.

Monorepo package building: Bundle multiple packages in large monorepos where build time compounds across dozens of projects. esbuild's speed makes it practical to rebuild all packages on every change without waiting minutes for completion.

Pros & Cons

Pros

  • +Exceptionally fast build times (10-100x faster than webpack/Rollup) without requiring cache warming
  • +Built-in support for TypeScript, JSX, CSS, and common formats without configuration overhead
  • +Simple API with sensible defaults that work for most projects immediately
  • +Active development and wide adoption as the foundation for modern frameworks like Vite
  • +Generates efficient output with automatic tree shaking, code splitting, and minification

Cons

  • No type checking for TypeScript (only strips types), requiring separate tsc runs for validation
  • Limited plugin ecosystem compared to webpack; complex transformations may not be possible
  • Less mature support for advanced features like module federation or custom chunk splitting strategies
  • Documentation can be terse for complex use cases; assumes familiarity with bundler concepts
  • Breaking changes between versions have occurred, requiring migration effort in some updates

Comparisons

Install

bash
npm install esbuild
bash
pnpm add esbuild
bash
bun add esbuild