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

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

Bun CLI tree-shaking always enabled

Tree-shaking is always true in Bun's bundler. The esbuild `--tree-shaking` flag is not applicable.

Bun version command

To see the version of Bun, run `bun --version`. The esbuild `--version` flag for the bundler is not applicable.

Bun CLI --drop flag supported

Bun CLI supports the `--drop` flag, same as esbuild.

Bun CLI --tsconfig-override replaces esbuild --tsconfig

Bun uses `--tsconfig-override` instead of esbuild's `--tsconfig`.

Bun CLI --root replaces esbuild --outbase

Bun uses `--root` instead of esbuild's `--outbase`.

Bun CLI --public-path supported

Bun CLI supports the `--public-path` flag, same as esbuild.

CLI syntax for bun build vs esbuild

The basic CLI syntax differs: esbuild uses `esbuild <entrypoint> --outdir=out --bundle` while Bun uses `bun build <entrypoint> --outdir=out`. Boolean flags like `--minify` take no argument in Bun. Flags that take a value, 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`.

Bun CLI --no-bundle flag

In Bun CLI, use `--no-bundle` to disable bundling. Bun always bundles by default, unlike esbuild which requires `--bundle`.

Bun CLI --define flag syntax

Bun's `--define` flag uses `--define K=V` syntax without a colon, whereas esbuild uses `--define:K=V`. Example: `bun build --define foo=bar` instead of `esbuild --define:foo=bar`.

Bun CLI --external flag syntax

Bun's `--external` flag uses `--external <pkg>` syntax without a colon, whereas esbuild uses `--external:<pkg>`. Example: `bun build --external react` instead of `esbuild --external:react`.

Bun CLI --format values

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

Bun CLI --loader flag syntax and supported loaders

Bun's `--loader` flag syntax is `--loader .ext:loader` (e.g., `bun build app.ts --loader .svg:text`), whereas esbuild uses `--loader:.ext=loader` (e.g., `esbuild app.ts --bundle --loader:.svg=text`). Bun supports a different set of built-in loaders than esbuild. The esbuild loaders `dataurl`, `binary`, `base64`, `copy`, and `empty` are not implemented in Bun.

Bun CLI --target replaces esbuild --platform

In Bun CLI, `--target` is used instead of esbuild's `--platform`, renamed for consistency with tsconfig. Bun's `--target` does not support `neutral`.

Bun CLI --asset-naming replaces esbuild --asset-names

Bun uses `--asset-naming` instead of esbuild's `--asset-names`, renamed for consistency with naming in the JS API.

Bun CLI --banner and --footer only apply to JS bundles

In Bun CLI, `--banner` and `--footer` flags only apply to JavaScript bundles, not CSS or other asset types.

Bun CLI --chunk-naming replaces esbuild --chunk-names

Bun uses `--chunk-naming` instead of esbuild's `--chunk-names`, renamed for consistency with naming in the JS API.

Bun CLI --color always enabled

In Bun CLI, color output is always enabled. The esbuild `--color` flag is not applicable.

Bun CLI --feature flag for compile-time dead-code elimination

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

Bun CLI --entry-naming replaces esbuild --entry-names

Bun uses `--entry-naming` instead of esbuild's `--entry-names`, renamed for consistency with naming in the JS API.

Bun CLI --ignore-dce-annotations replaces esbuild --ignore-annotations

Bun uses `--ignore-dce-annotations` instead of esbuild's `--ignore-annotations`.

Bun CLI --jsx-runtime replaces esbuild --jsx

Bun uses `--jsx-runtime <runtime>` instead of esbuild's `--jsx`. Supports `"automatic"` (uses jsx transform) and `"classic"` (uses `React.createElement`).

Bun CLI JSX default handling from tsconfig.json

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`.

Bun CLI --jsx-factory, --jsx-fragment, --jsx-import-source supported

Bun CLI supports `--jsx-factory`, `--jsx-fragment`, and `--jsx-import-source` flags, same as esbuild.

Bun CLI --keep-names supported

Bun CLI supports the `--keep-names` flag, same as esbuild.

Bun CLI --metafile supported

Bun CLI supports the `--metafile` flag, same as esbuild.

Bun CLI minification granular flags

Bun CLI supports `--minify-whitespace`, `--minify-identifiers`, and `--minify-syntax` flags for granular control over minification, same as esbuild.

Running dev server with HTML file

To start the development server, run `bun ./index.html`. The server provides automatic bundling, multi-entry support, TypeScript and JSX support, CSS bundling and minification, and asset management with path rewriting.

Multi-page app (MPA) multiple entry points

To support multiple HTML entry points, pass them all to `bun`: `bun ./index.html ./about.html`. This serves index.html at / and about.html at /about.

Glob patterns for HTML entry points

You can use glob patterns ending in .html to specify multiple HTML files: `bun ./**/*.html`. Bun will discover all matching HTML files and serve them as separate routes.

Environment variable inlining in production build CLI

When building for production with `bun build`, use the --env flag to inline environment variables: `bun build ./index.html --outdir=dist --env=inline` to inline all environment variables, or `bun build ./index.html --outdir=dist --env=PUBLIC_*` to only inline vars with a specific prefix (recommended).

Browser console logs to terminal with --console flag

Bun's dev server can stream console logs from the browser to the terminal by passing the --console CLI flag: `bun ./index.html --console`. Each call to console.log or console.error is broadcast to the terminal, so browser errors show up where you run the server. Internally, this reuses the WebSocket connection from hot module replacement (HMR).

Dev server keyboard shortcuts

While the dev server is running: `o + Enter` opens in browser, `c + Enter` clears console, `q + Enter` or `Ctrl+C` quits the server.

Production build with bun build command

Use `bun build ./index.html --minify --outdir=dist` to create optimized production bundles.

Watch mode with bun build --watch

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

bun build CLI basic syntax

The CLI command to bundle code is: `bun build <entry> --outdir ./out`. Multiple entrypoints can be provided as separate arguments.

Watch mode for incremental rebuilds

Watch mode is enabled with --watch flag: `bun build ./index.tsx --outdir ./out --watch`. Supports incremental rebuilds like the runtime and test runner.

--minify CLI flag

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

--production CLI flag enables minification

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

--minify-whitespace CLI flag

The --minify-whitespace flag removes all unnecessary whitespace, newlines, and formatting from the output. Usage: bun build ./index.ts --minify-whitespace --outfile=out.js

--minify-syntax CLI flag

The --minify-syntax flag rewrites JavaScript syntax to shorter equivalent forms and performs constant folding, dead code elimination, and other optimizations. Usage: bun build ./index.ts --minify-syntax --outfile=out.js

--minify-identifiers CLI flag

The --minify-identifiers flag renames local variables and function names to shorter identifiers using frequency-based optimization. Usage: bun build ./index.ts --minify-identifiers --outfile=out.js

--drop=debugger CLI flag

The --drop=debugger flag removes debugger statements from code during minification.

--drop=console CLI flag

The --drop=console flag removes all console.* method calls from code during minification. Calls are replaced with void 0.

--drop=<name> CLI flag

The --drop=<name> flag removes calls to specified global functions and their methods. Example: --drop=assert removes all assert() and assert.* calls.

--keep-names flag for minification

The --keep-names flag preserves the .name property on functions and classes while still minifying the identifiers themselves. Useful for debugging. Usage: bun build ./index.ts --minify --keep-names --outfile=out.js

Give your agent this brain