← 返回命令列表

Linux command

bun-build 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Bundle JavaScript/TypeScript file

bun build [./src/index.ts] --outdir [./dist]

Create standalone executable

bun build [./server.ts] --compile --outfile [server]

Bundle with minification

bun build [./src/index.ts] --outdir [./dist] --minify

Generate source maps

bun build [./src/index.ts] --outdir [./dist] --sourcemap

Bundle for Node.js target

bun build [./src/index.ts] --outdir [./dist] --target [node]

Mark packages as external

bun build [./src/index.ts] --outdir [./dist] --external [react]

Bundle multiple entrypoints

bun build [./src/index.ts] [./src/worker.ts] --outdir [./dist]

说明

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().

参数

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

FAQ

What is the bun-build command used for?

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().

How do I run a basic bun-build example?

Run `bun build [./src/index.ts] --outdir [./dist]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --outdir _directory_ do in bun-build?

Output directory for bundled files