new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Bun · Bundler · all subjects

cli flags & behavior

41 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

--external syntax difference: no colon

Bun uses --external <pkg> without a colon, whereas esbuild uses --external:<pkg>. Example: esbuild --external:react becomes bun build --external react.

--define syntax difference: no colon

Bun uses --define K=V without a colon, whereas esbuild uses --define:K=V. Example: esbuild --define:foo=bar becomes bun build --define foo=bar.

--format supported values in Bun

Bun supports format values of "esm", "cjs", and "iife". esbuild defaults to "iife" but Bun does not specify a default in this comparison.

CLI boolean flags and argument syntax

In Bun's CLI, boolean flags like --minify take no argument. Flags that take one, like --outdir <path>, can be written as --outdir out or --outdir=out. Some flags, like --define, can be repeated: --define foo=bar --define bar=baz.

--bundle flag not needed in Bun CLI

Bun always bundles by default; use --no-bundle to disable it. Unlike esbuild which requires --bundle, this is not needed.

--target replaces --platform in Bun CLI

--platform in esbuild is renamed to --target in Bun for consistency with tsconfig. Bun's --target does not support the "neutral" value.

--sourcemap supported values

Bun's --sourcemap supports values of "linked" (the default when no value is given), "external", "inline", and "none". It does not support esbuild's "both".

--target syntax downleveling not supported

Bun's bundler does not support syntax downleveling, unlike esbuild's --target flag which can downlevel syntax for target environments.

--asset-naming renamed from --asset-names

--asset-names in esbuild is renamed to --asset-naming in Bun for consistency with naming in the JS API.

--chunk-naming renamed from --chunk-names

--chunk-names in esbuild is renamed to --chunk-naming in Bun for consistency with naming in the JS API.

--entry-naming renamed from --entry-names

--entry-names in esbuild is renamed to --entry-naming in Bun for consistency with naming in the JS API.

--feature flag enables compile-time dead-code elimination

--feature is a Bun-specific CLI flag that enables feature flags for compile-time dead-code elimination through import { feature } from "bun:bundle".

--ignore-dce-annotations replaces --ignore-annotations

--ignore-annotations in esbuild is renamed to --ignore-dce-annotations in Bun.

--jsx-runtime supported values

--jsx-runtime in Bun supports "automatic" (uses jsx transform) and "classic" (uses React.createElement).

--jsx-dev behavior determined by tsconfig

Bun reads compilerOptions.jsx from tsconfig.json to determine a default. If compilerOptions.jsx is "react-jsx", or if NODE_ENV=production, Bun uses the jsx transform. Otherwise, it uses jsxDEV. The bundler does not support "preserve".

--root replaces --outbase

--outbase in esbuild is renamed to --root in Bun.

--tsconfig-override replaces --tsconfig

--tsconfig in esbuild is renamed to --tsconfig-override in Bun.

--color flag always enabled in Bun

--color is always enabled in Bun and cannot be disabled via CLI flag.

--tree-shaking always true in Bun

Tree-shaking is always enabled in Bun and cannot be disabled.

Unsupported esbuild CLI flags in Bun

The following esbuild CLI flags are not supported in Bun: --analyze, --allow-overwrite, --certfile, --charset, --global-name, --inject, --keyfile, --legal-comments, --log-level, --log-limit, --log-override, --main-fields, --mangle-cache, --mangle-props, --mangle-quoted, --out-extension, --preserve-symlinks, --pure, --reserve-props, --resolve-extensions, --serve, --servedir, --source-root, --sourcefile, --sources-content, --supported, --version (use bun --version instead).

bun build CLI command syntax

The CLI command is: bun build <entry> --outdir ./out. For example: bun build ./index.tsx --outdir ./build

Watch mode for incremental rebuilds

Use the --watch flag for incremental rebuilds. CLI example: bun build ./index.tsx --outdir ./out --watch

Minify standalone HTML with --minify flag

Add --minify to the bun build command to minify the JavaScript and CSS in standalone HTML output. Example: bun build --compile --target=browser --minify ./index.html --outdir=dist. This also works with the JavaScript API by setting minify: true in the Bun.build() options.

Inline environment variables in standalone HTML

Use --env=inline flag with bun build to inline environment variables into the bundled JavaScript. Example: API_URL=https://api.example.com bun build --compile --target=browser --env=inline ./index.html --outdir=dist. Bun replaces references to process.env.API_URL in JavaScript with the literal value at build time.

Run HTML dev server with bun command

To start the development server, pass an HTML file to `bun`. For example, `bun ./index.html` starts a dev server with automatic bundling, serving at http://localhost:3000/ by default.

Watch mode for automatic rebuilding

Run `bun build --watch` to watch for changes and rebuild automatically. This works well for library development.

Echo browser console logs to terminal

Bun's dev server can stream console logs from the browser to the terminal. Pass the `--console` CLI flag to `bun ./index.html --console` to enable this feature. Each `console.log` or `console.error` call from the browser is broadcast to the terminal where the server was started, helping with debugging and AI agent monitoring.

Browser console log transport mechanism

Bun reuses the existing WebSocket connection from hot module replacement (HMR) to send console logs from the browser to the terminal.

Edit files in browser with Chrome DevTools

Bun's frontend dev server supports Automatic Workspace Folders in Chrome DevTools, allowing you to save edits to files directly from the browser.

Dev server keyboard shortcuts

While the Bun dev server is running, use these keyboard shortcuts: `o + Enter` to open in browser, `c + Enter` to clear console, `q + Enter` or `Ctrl+C` to quit the server.

Disable macros with --no-macros flag

The --no-macros flag disables macros entirely and produces a build error when macro invocations are encountered.

--minify CLI flag enables all minification modes

The --minify flag enables all three minification modes: whitespace minification, syntax minification, and identifier minification. Example: bun build ./index.ts --minify --outfile=out.js

--production flag enables minification and sets NODE_ENV

The --production flag automatically enables minification and also sets process.env.NODE_ENV to 'production' and enables production-mode JSX import and transform. Example: bun build ./index.ts --production --outfile=out.js

Granular minification CLI flags: --minify-whitespace, --minify-syntax, --minify-identifiers

Individual minification modes can be enabled separately: --minify-whitespace removes unnecessary whitespace; --minify-syntax rewrites syntax to shorter forms; --minify-identifiers renames identifiers to shorter names. Modes can be combined, for example: bun build ./index.ts --minify-whitespace --minify-syntax --outfile=out.js

--minify-whitespace mode removes unnecessary whitespace and comments

The --minify-whitespace mode removes all unnecessary whitespace, newlines, formatting, and comments (except license comments marked with /*!). It also optimizes semicolons to insert only when necessary and removes spaces around operators.

--minify-syntax mode performs constant folding, dead code elimination, and syntax transformations

The --minify-syntax mode rewrites JavaScript syntax to shorter equivalent forms, performs constant folding (evaluates constant expressions at compile time), dead code elimination, and dozens of optimizations including boolean algebra, undefined shortening, infinity shortening, typeof optimizations, number formatting, arithmetic and bitwise constant folding, string concatenation, template literal folding, and many others.

--minify-identifiers renames local variables using frequency-based optimization

The --minify-identifiers mode renames local variables and function names to shorter identifiers using frequency-based optimization. Most frequently used identifiers get the shortest names, ordered by character frequency in source. Single-character names use a-z, A-Z, and _ (53 names, with $ reserved). Two-character names can use digits (up to 3,456 names). JavaScript keywords, reserved words, global identifiers, named exports, and CommonJS names (exports, module) are preserved.

--keep-names flag preserves function and class names during minification

The --keep-names flag preserves the .name property on functions and classes while still minifying the identifiers themselves. This helps with debugging. Used with CLI: bun build ./index.ts --minify --keep-names --outfile=out.js Or in API: await Bun.build({ entrypoints: ['./index.ts'], outdir: './out', minify: { identifiers: true, keepNames: true } })

--drop=debugger removes debugger statements

The --drop=debugger flag removes all debugger statements from the output. Example: function test() { debugger; return x; } becomes function test(){return x}

--drop=console removes all console method calls

The --drop=console flag removes all console.* method calls from the output and replaces them with void 0. Examples: console.log('debug'); becomes void 0;; x = console.error('error'); becomes x=void 0;

--drop=<name> removes calls to specified global functions

The --drop=<name> flag removes calls to a specified global function and its methods. Example: with --drop=assert, assert(condition); becomes void 0; and assert.equal(a, b); becomes void 0;

Give your agent this brain