property
CompileBuildOptions.trim
Remove the Bun and Node.js APIs your code never calls from the executable.
With aot, the compiler knows which APIs the program uses, and Bun removes every other feature. Without aot, Bun only removes the command-line tools. An object does what true does, with the options in TrimOptions.
Removing a feature removes its code, not its names: every global, constructor, prototype, property and constant is still there. A call, a new, a getter or a setter of a removed feature throws an Error whose message has the API's name and whose code is "ERR_FEATURE_REMOVED". Importing a removed built-in module, such as bun:sqlite, throws an Error whose code is "ERR_MODULE_NOT_FOUND". If code reaches a removed feature any other way, the process prints the feature and exits with code 70.
The build fails if allow has an unknown name, or locales has a locale that Bun has no data for.
Equivalent CLI flag: --trim
await Bun.build({
entrypoints: ["./server.ts"],
compile: { outfile: "./server", aot: true, trim: { allow: ["sqlite"], locales: ["en"] } },
});