CodeVetter · Repo Unpack · Feature catalog
evanw/esbuild
User-facing features are the CLI flag set, the Go and JavaScript build/transform/context APIs, plugins, a local HTTP dev server, polling watch mode, and packaging for many OS/CPU targets plus WASM. Loaders cover JS, JSX, TS, TSX, CSS (including CSS modules), JSON, and several asset loaders. React appears only as a test dependency in scripts/package.json, not as a product UI.
- CLI help in main.go documents --bundle, --define:K=V, --external:M, --format=iife|cjs|esm, --loader, --minify, --outdir/--outfile, --packages, --platform=browser|node|neutral, --serve, --sourcemap, --splitting, --target, and --watch / --watch=forever.
- The same help lists loaders base64, binary, copy, css, dataurl, empty, file, global-css, js, json, jsx, local-css, text, ts, and tsx. Default extension mapping in bundler.go assigns .js/.mjs/.cjs to JS, .jsx to JSX, and .json to JSON.
- Advanced CLI flags include --analyze, --banner/--footer, --certfile/--keyfile, --drop, --jsx and --jsx-import-source (default react), --mangle-props, --metafile, --minify-whitespace/identifiers/syntax, --pure, --supported, --tree-shaking, --tsconfig, and --tsconfig-raw.
- pkg/api.BuildOptions-style operations are Build (one-shot), Transform (string in, code/map/legal comments out), and Context for repeated Rebuild, Watch, and Serve. Plugin hooks are Setup plus OnStart, OnEnd, OnResolve, OnLoad, and OnDispose.
- lib/npm/node.ts exports build, context, transform, formatMessages, analyzeMetafile, and the sync twins buildSync, transformSync, and formatMessagesSync. Sync calls prefer a worker_threads service unless ESBUILD_WORKER_THREADS is 0 or the thread is already the internal worker.
- The service protocol commands handled in service.go are build, transform, resolve, rebuild, watch, serve, cancel, dispose, error, format-msgs, and analyze-metafile. Resolve kinds encoded later include entry-point, import-statement, require-call, dynamic-import, require-resolve, import-rule, composes-from, and url-token.
- Serve mode is a local HTTP server. It overlays in-memory build outputs on servedir, serves index.html or a generated directory listing, and special-cases GET /esbuild with Accept text/event-stream. HTTPS requires both keyfile and certfile. CORS origins support a single * wildcard.
- Watch mode is a polling scanner, not fsnotify and not cgo. It sleeps 100ms, checks up to 16 recent paths every tick plus at least 64 other paths, and aims to scan a large project about every 2 seconds.
- When bundling, an unspecified format becomes IIFE for platform browser, CommonJS for node, and ESM for neutral. --splitting is rejected unless the output format is ESM. external and alias are rejected unless bundle is set.
- Yarn PnP resolution is implemented in internal/resolver/yarnpnp.go against the Yarn PnP spec (package registry, fallback pool, ignore pattern). Zip contents are read through internal/fs/fs_zip.go.
- The JS API locates a platform binary via knownWindowsPackages, knownUnixlikePackages, and knownWebAssemblyFallbackPackages (android arm, android x64, and openharmony arm64 are WASM fallbacks). ESBUILD_BINARY_PATH overrides the path, except the hard-coded ignore of /usr/bin/esbuild.
- scripts/package.json depends on react 17.0.1, typescript 4.7.4, source-map, and unicode data. Those are test/tooling dependencies. The product itself has no React UI; JSX support defaults the factory to React.createElement.