Add a banner to the bundled code such as "use client";
type
BuildConfig
Referenced types
interface CompileBuildConfig
- 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" - compile: boolean | CompileBuildOptions | Target
Create a standalone executable
When
true, creates an executable for the current platform. When a target string, creates an executable for that platform.// Create executable for current platform await Bun.build({ entrypoints: ['./app.js'], compile: { target: 'linux-x64', }, outfile: './my-app' }); // Cross-compile for Linux x64 await Bun.build({ entrypoints: ['./app.js'], compile: 'linux-x64', outfile: './my-app' }); - conditions?: string | string[]
package.json
exportsconditions used when resolving importsEquivalent to
--conditionsinbun buildorbun 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.FOOreferences 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.
- jsx?: { development: boolean; factory: string; fragment: string; importSource: string; runtime: 'classic' | 'automatic'; sideEffects: boolean }
JSX configuration options
- minify?: boolean | { identifiers: boolean; keepNames: boolean; syntax: boolean; whitespace: boolean }
Whether to enable minification.
Use
true/falseto enable/disable all minification options. Alternatively, you can pass an object for granular control over certain minifications. - sourcemap?: boolean | 'none' | 'linked' | 'external' | 'inline'
Specifies if and how to generate source maps.
"none"- No source maps are generated"linked"- A separate*.ext.mapfile is generated alongside each*.extfile. A//# sourceMappingURLcomment is added to the output file to link the two. Requiresoutdirto 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//# sourceMappingURLcomment is added to the output file.
trueandfalseare 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 to
false, returns a BuildOutput with{success: false}
- When set to
- tsconfig?: string
Custom tsconfig.json file path to use for path resolution. Equivalent to
--tsconfig-overridein the CLI.await Bun.build({ entrypoints: ['./src/index.ts'], tsconfig: './custom-tsconfig.json' });
interface NormalBuildConfig
- 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
exportsconditions used when resolving importsEquivalent to
--conditionsinbun buildorbun 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.FOOreferences 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.
- jsx?: { development: boolean; factory: string; fragment: string; importSource: string; runtime: 'classic' | 'automatic'; sideEffects: boolean }
JSX configuration options
- minify?: boolean | { identifiers: boolean; keepNames: boolean; syntax: boolean; whitespace: boolean }
Whether to enable minification.
Use
true/falseto enable/disable all minification options. Alternatively, you can pass an object for granular control over certain minifications. - sourcemap?: boolean | 'none' | 'linked' | 'external' | 'inline'
Specifies if and how to generate source maps.
"none"- No source maps are generated"linked"- A separate*.ext.mapfile is generated alongside each*.extfile. A//# sourceMappingURLcomment is added to the output file to link the two. Requiresoutdirto 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//# sourceMappingURLcomment is added to the output file.
trueandfalseare 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 to
false, returns a BuildOutput with{success: false}
- When set to
- tsconfig?: string
Custom tsconfig.json file path to use for path resolution. Equivalent to
--tsconfig-overridein the CLI.await Bun.build({ entrypoints: ['./src/index.ts'], tsconfig: './custom-tsconfig.json' });