bun-build
Bundle JavaScript and TypeScript for production
TLDR
Bundle JavaScript/TypeScript file
SYNOPSIS
bun build entrypoints [options]
DESCRIPTION
bun build is Bun's fast native bundler for JavaScript and TypeScript. It bundles code for production, generates standalone executables, and supports both server and client code in a single command.
The bundler automatically performs tree-shaking to eliminate unused code. It can target multiple runtimes including browsers, Node.js, and Bun itself. The --compile flag creates self-contained executables with the Bun runtime embedded, enabling distribution without requiring users to install Bun. Code splitting, source maps, and minification are supported through command-line flags or the equivalent JavaScript API via Bun.build().
PARAMETERS
--outdir directory
Output directory for bundled files--outfile file
Output file path (for single output)--compile
Create standalone executable with embedded Bun runtime--minify
Enable minification--sourcemap
Generate source maps (external, inline, or none)--target runtime
Target runtime: browser, bun, or node--external package
Exclude package from bundle--splitting
Enable code splitting--format type
Output format: esm or cjs--define key=value
Define global constants--loader ext:loader
Configure file type loaders
JAVASCRIPT API
entrypoints: ['./src/index.js'],
outdir: './build',
minify: true,
})
CAVEATS
Standalone executables include a copy of the Bun runtime, increasing file size. Tree-shaking is always enabled. Some npm packages may not bundle correctly due to dynamic imports.
