esbuild Command: Bundle & Compile in CI
esbuild bundles and minifies JS/TS extremely fast via a Go-based core.
esbuild is a Go-powered bundler and compiler used in CI to build JS/TS bundles in a fraction of the time of older tools. As a CLI it transforms and bundles entry points, with flags for platform, target, minification, and source maps.
Common flags
--bundle- inline imported dependencies into the output--outfile=FILE/--outdir=DIR- single-file vs multi-file output--minify- minify the output (whitespace, identifiers, syntax)--platform=browser|node|neutral- resolution and globals strategy--target=es2020,node18- down-level syntax to these targets--sourcemap- emit a source map (inline/externalvariants)--format=esm|cjs|iife- output module format
Example in CI
Bundle and minify a TypeScript entry point for Node in a CI build step:
shell
esbuild src/index.ts --bundle --platform=node --target=node18 --minify --sourcemap --outfile=dist/index.jsCommon errors in CI
- Could not resolve "X" - missing dependency or wrong --platform
- No loader is configured for ".css" files - add a loader or plugin
- Transform failed with N errors - a syntax error in source
- The package "esbuild" could not be found / platform binary mismatch
Key takeaways
--bundleplus--platform/--targetdefine the bundling behavior.- esbuild is fast enough to bundle on every CI run without caching.
- "Could not resolve" usually means a missing dep or wrong platform setting.
Related guides
swc Command: Fast JS/TS Compile in CIswc is a Rust-based JS/TS compiler. Reference for --out-dir, --config-file, --source-maps, -C options, and th…
rollup Command: Bundle Libraries in CIrollup bundles ES modules into optimized output. Reference for -c, -i, -o, --format, --sourcemap, --watch, an…
vite build Command: Build Frontends in CIvite build produces a production bundle. Reference for --mode, --config, --outDir, --base, --sourcemap, and t…