Skip to content
Latchkey

esbuild --bundle --minify: Fast Bundling

esbuild --bundle --minify bundles and minifies your entry into one output in a fraction of the time other bundlers take.

esbuild is favored in CI for its speed. The flags are explicit: you tell it to bundle, minify, and where to write, and it does exactly that.

What it does

esbuild --bundle inlines imported modules into the output; --minify shrinks it. You set the environment with --platform and --target, and the output with --outfile or --outdir. It is a single fast pass with no config file required.

Common usage

Terminal
esbuild src/index.ts --bundle --minify --outfile=dist/index.js
esbuild src/index.ts --bundle --platform=node --target=node18 \
  --outfile=dist/server.js
# code-split ESM with an out directory
esbuild src/index.ts --bundle --splitting --format=esm --outdir=dist

Options

FlagWhat it does
--bundleInline imports into the output
--minifyMinify the output
--outfile=<f>Single output file
--outdir=<d>Output directory (needed for splitting)
--platform=<p>browser (default), node, or neutral
--target=<t>Syntax target, e.g. es2020, node18
--sourcemapEmit a source map
--external:<pkg>Leave a package out of the bundle

In CI

For Node builds set --platform=node so built-ins are not bundled, and --external for anything shipped separately. esbuild is fast enough that caching matters less, but pin the esbuild version since a native binary mismatch across runners can fail install.

Common errors in CI

"[ERROR] Could not resolve \"X\"" means the import is not installed or the path is wrong; add it or mark it --external. "The entry point ... cannot be marked as external" means an --external pattern is too broad. "Cannot find module \"@esbuild/linux-x64\"" on a runner means the platform-specific binary was not installed; run a clean install rather than copying node_modules across OSes.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →