Skip to content

bun build CLI Usage

bash
bun build <entry points>

General Configuration

--productionboolean
Set NODE_ENV=production and enable minification
--bytecodeboolean
Use a bytecode cache when compiling
--targetstring default: browser
Intended execution environment for the bundle. One of browser, bun, or node
--conditionsstring
Pass custom resolution conditions
--envstring default: disable
Inline environment variables into the bundle as process.env.${name}. To inline variables matching a prefix, use a glob like FOO_PUBLIC_*

Output & File Handling

--outdirstring default: dist
Output directory (used when building multiple entry points)
--outfilestring
Write output to a specific file
--sourcemapstring default: none
Generate source maps. One of linked, inline, external, or none
--bannerstring
Add a banner to the output (e.g. "use client" for React Server Components)
--footerstring
Add a footer to the output (e.g. // built with bun!)
--formatstring default: esm
Module format of the output bundle. One of esm, cjs, or iife

File Naming

--entry-namingstring default: [dir]/[name].[ext]
Customize entry point filenames
--chunk-namingstring default: [name]-[hash].[ext]
Customize chunk filenames
--asset-namingstring default: [name]-[hash].[ext]
Customize asset filenames

Bundling Options

--rootstring
Root directory used when bundling multiple entry points
--splittingboolean
Enable code splitting for shared modules
--public-pathstring
Prefix to be added to import paths in bundled code
--externalstring
Exclude modules from the bundle (supports wildcards). Alias: -e
--packagesstring default: bundle
How to treat dependencies: external or bundle
--no-bundleboolean
Transpile only — do not bundle
--css-chunkingboolean
Chunk CSS files together to reduce duplication (only when multiple entry points import CSS)

Minification & Optimization

--emit-dce-annotationsboolean default: true
Re-emit Dead Code Elimination annotations. Disabled when --minify-whitespace is used
--minifyboolean
Enable all minification options
--minify-syntaxboolean
Minify syntax and inline constants
--minify-whitespaceboolean
Minify whitespace
--minify-identifiersboolean
Minify variable and function identifiers
--keep-namesboolean
Preserve original function and class names when minifying

Development Features

--watchboolean
Rebuild automatically when files change
--no-clear-screenboolean
Don’t clear the terminal when rebuilding with --watch
--react-fast-refreshboolean
Enable React Fast Refresh transform (for development testing)

Standalone Executables

--compileboolean
Generate a standalone Bun executable containing the bundle. Implies --production
--compile-exec-argvstring
Prepend arguments to the standalone executable’s execArgv

Windows Executable Details

--windows-hide-consoleboolean
Prevent a console window from opening when running a compiled Windows executable
--windows-iconstring
Set an icon for the Windows executable
--windows-titlestring
Set the Windows executable product name
--windows-publisherstring
Set the Windows executable company name
--windows-versionstring
Set the Windows executable version (e.g. 1.2.3.4)
--windows-descriptionstring
Set the Windows executable description
--windows-copyrightstring
Set the Windows executable copyright notice

Experimental & App Building

--appboolean
(EXPERIMENTAL) Build a web app for production using Bun Bake
--server-componentsboolean
(EXPERIMENTAL) Enable React Server Components
--debug-dump-server-filesboolean
When --app is set, dump all server files to disk even for static builds
--debug-no-minifyboolean
When --app is set, disable all minification

Bun by www.bunjs.com.cn 편집