← Back to docsRecipe
esbuild primer
esbuild is an extremely fast JavaScript bundler written in Go. It compiles TypeScript, JSX, and modern ESM down to compact bundles orders of magnitude faster than webpack or Rollup.
Why esbuild?
A single-threaded esbuild run can process hundreds of modules per millisecond. It achieves this through parallel parsing, zero-copy AST construction, and a hand-tuned Go core that avoids the overhead of JavaScript-based toolchains.
Quick start
npm install esbuild
// build.js
require('esbuild').build({
entryPoints: ['src/app.tsx'],
bundle: true,
outfile: 'dist/app.js',
platform: 'browser',
target: 'es2020',
}).catch(() => process.exit(1))Key flags
- --bundle — inline all dependencies into one file
- --minify — shorten identifiers and remove whitespace
- --sourcemap — emit a source map for debugging
- --target — set the ECMAScript output version
- --format=esm — output ES modules instead of CJS
When to use it
esbuild shines for library bundling, serverless function packaging, and dev-server transpilation. For complex applications with code-splitting and hot-module replacement, Vite (which uses esbuild internally) is often a better fit.