bun build CLI 用法
bash
bun build <entry points>常规配置
--productionboolean 设置
NODE_ENV=production 并启用压缩 --bytecodeboolean 编译时使用字节码缓存
--targetstring default: browser 打包的预期执行环境。可选值:
browser、bun 或 node--conditionsstring 传递自定义解析条件
--envstring default: disable 将环境变量内联到打包中,形式为
process.env.${name}。要内联匹配前缀的变量,使用通配符如 FOO_PUBLIC_*输出与文件处理
--outdirstring default: dist 输出目录(用于构建多个入口点时)
--outfilestring 将输出写入指定文件
--sourcemapstring default: none 生成 source map。可选值:
linked、inline、external 或 none--bannerstring 在输出中添加 banner(例如 React Server Components 的
"use client") --footerstring 在输出中添加 footer(例如
// built with bun!) --formatstring default: esm 输出打包的模块格式。可选值:
esm、cjs 或 iife文件命名
--entry-namingstring default: [dir]/[name].[ext] 自定义入口点文件名
--chunk-namingstring default: [name]-[hash].[ext] 自定义 chunk 文件名
--asset-namingstring default: [name]-[hash].[ext] 自定义资源文件名
打包选项
--rootstring 打包多个入口点时使用的根目录
--splittingboolean 启用共享模块的代码分割
--public-pathstring 打包代码中导入路径的前缀
--externalstring 从打包中排除模块(支持通配符)。别名:
-e--packagesstring default: bundle 如何处理依赖:
external 或 bundle--no-bundleboolean 仅转译,不打包
--css-chunkingboolean 将 CSS 文件分块以减少重复(仅当多个入口点导入 CSS 时)
压缩与优化
--emit-dce-annotationsboolean default: true 重新发出死代码消除注释。使用
--minify-whitespace 时禁用 --minifyboolean 启用所有压缩选项
--minify-syntaxboolean 压缩语法和内联常量
--minify-whitespaceboolean 压缩空白字符
--minify-identifiersboolean 压缩变量和函数标识符
--keep-namesboolean 压缩时保留原始函数和类名
开发功能
--watchboolean 文件更改时自动重新构建
--no-clear-screenboolean 使用
--watch 重新构建时不清除终端屏幕 --react-fast-refreshboolean 启用 React 快速刷新转换(用于开发测试)
独立可执行文件
--compileboolean 生成包含打包的独立 Bun 可执行文件。隐含
--production--compile-exec-argvstring 在独立可执行文件的
execArgv 前添加参数 Windows 可执行文件详情
--windows-hide-consoleboolean 运行编译后的 Windows 可执行文件时防止打开控制台窗口
--windows-iconstring 设置 Windows 可执行文件的图标
--windows-titlestring 设置 Windows 可执行文件的产品名称
--windows-publisherstring 设置 Windows 可执行文件的公司名称
--windows-versionstring 设置 Windows 可执行文件版本(例如
1.2.3.4) --windows-descriptionstring 设置 Windows 可执行文件描述
--windows-copyrightstring 设置 Windows 可执行文件版权声明
实验性与应用构建
--appboolean(实验性) 使用 Bun Bake 构建 Web 应用以进行生产
--server-componentsboolean(实验性) 启用 React Server Components
--debug-dump-server-filesboolean 设置
--app 时,即使是静态构建也将所有服务器文件转储到磁盘 --debug-no-minifyboolean 设置
--app 时,禁用所有压缩