Add a banner to the bundled code such as "use client";
Symbol
BuildConfig
interface BuildConfig
- bytecode?: boolean
Generate bytecode for the output. This can dramatically improve cold start times, but will make the final output larger and slightly increase memory usage.
Bytecode is currently only supported for CommonJS (
format: "cjs"
).Must be
target: "bun"
- conditions?: string | string[]
package.json
exports
conditions used when resolving importsEquivalent to
--conditions
inbun build
orbun run
.https://nodejs.org/api/packages.html#exports
- env?: 'inline' | 'disable' | `${string}*`
Controls how environment variables are handled during bundling.
Can be one of:
"inline"
: Injects environment variables into the bundled output by convertingprocess.env.FOO
references to string literals containing the actual environment variable values"disable"
: Disables environment variable injection entirely- A string ending in
*
: Inlines environment variables that match the given prefix. For example,"MY_PUBLIC_*"
will only include env vars starting with "MY_PUBLIC_"
Bun.build({ env: "MY_PUBLIC_*", entrypoints: ["src/index.ts"], })
- format?: 'esm' | 'cjs' | 'iife'
Output module format. Top-level await is only supported for
"esm"
.Can be:
"esm"
"cjs"
(experimental)"iife"
(experimental)
- ignoreDCEAnnotations?: boolean
Ignore dead code elimination/tree-shaking annotations such as @PURE and package.json "sideEffects" fields. This should only be used as a temporary workaround for incorrect annotations in libraries.
- minify?: boolean | { identifiers: boolean; syntax: boolean; whitespace: boolean }
Whether to enable minification.
Use
true
/false
to enable/disable all minification options. Alternatively, you can pass an object for granular control over certain minifications. - sourcemap?: boolean | 'external' | 'none' | 'linked' | 'inline'
Specifies if and how to generate source maps.
"none"
- No source maps are generated"linked"
- A separate*.ext.map
file is generated alongside each*.ext
file. A//# sourceMappingURL
comment is added to the output file to link the two. Requiresoutdir
to be set."inline"
- an inline source map is appended to the output file."external"
- Generate a separate source map file for each input file. No//# sourceMappingURL
comment is added to the output file.
true
andfalse
are aliases for"inline"
and"none"
, respectively. - throw?: boolean
When set to
true
, the returned promise rejects with an AggregateError when a build failure happens. When set tofalse
, thesuccess
property of the returned object will befalse
when a build failure happens. This defaults totrue
.