Skip to content
Latchkey

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/external variants)
  • --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.js

Common 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

  • --bundle plus --platform/--target define 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →