10LOC

#build-tools

Bunadvanced

On-the-fly TS/JSX transforms with Bun.Transpiler

const transpiler = new Bun.Transpiler({ loader: "tsx" });

const source = `
  interface Props { name: string }
  export const Greeting = (props: Props) => <h1>Hello, {props.name}!</h1>;

Bun.Transpiler exposes Bun's own TS/JSX-to-JS compiler as a callable class, for transforming source strings at runtime without shelling out to a build step.

Bunadvanced

Bundling programmatically with Bun.build()

try {
  const result = await Bun.build({
    entrypoints: ["./src/index.ts"],
    outdir: "./dist",
    minify: true,

Bun.build() is the bun build CLI as a JS function, returning artifacts you can inspect, write, or serve directly instead of shelling out.

Bunintermediate

Bun.$ shell scripting for cross-platform build scripts

import { $ } from "bun";

await $`rm -rf dist`;
await $`mkdir dist`;

Bun's $ template literal runs a small bash-like shell with no /bin/sh dependency, so build scripts behave identically on Windows, macOS, and Linux.