Skip to content

secondsky/claude-skills / plugins/bun/skills/bun-bundler

bun-bundler

Verified

This skill should be used when the user asks about "bun build", "Bun.build", "bundling with Bun", "code splitting", "tree shaking", "minification", "sourcemaps", "bundle optimization", "esbuild alternative", "building for production", "bundling TypeScript", "bundling for browser", "bundling for Node", or JavaScript/TypeScript bundling with Bun.

FileKindSize
SKILL.mdskill md7.2 KB
references/options.mdmarkdown5.2 KB

references/options.md

View on GitHub
# Bun.build Complete Options Reference

## All Options

```typescript
interface BuildConfig {
  // Entry points
  entrypoints: string[];

  // Output
  outdir?: string;
  outfile?: string;  // Single file output

  // Target
  target?: "browser" | "bun" | "node";

  // Format
  format?: "esm" | "cjs" | "iife";

  // Minification
  minify?: boolean | {
    whitespace?: boolean;
    identifiers?: boolean;
    syntax?: boolean;
  };

  // Code splitting
  splitting?: boolean;

  // Source maps
  sourcemap?: "none" | "inline" | "external" | "linked";

  // Naming
  naming?: {
    entry?: string;
    chunk?: string;
    asset?: string;
  } | string;

  // Root directory
  root?: string;

  // Public path
  publicPath?: string;

  // Define
  define?: Record<string, string>;

  // External
  external?: string[];

  // Loaders
  loader?: Record<string, Loader>;

  // Plugins
  plugins?: Plugin[];

  // Conditions
  conditions?: string[];

  // Drop
  drop?: string[];

  // Banner/Footer
  banner?: string;
  footer?: string;

  // Throw on error
  throw?: boolean;

  // Packages
  packages?: "bundle" | "external";

  // Bytecode (Bun target only)
  bytecode?: boolean;

  // Environment files
  emitDCEAnnotations?: boolean;
  ignoreDCEAnnotations?: boolean;

  // JSX
  jsx?: "automatic" | "classic" | "preserve";
  jsxFactory?: string;
  jsxFragment?: string;
  jsxImportSource?: string;
  jsxSideEffects?: boolean;
}
```

## Entry Points

```typescript
// Single entry
await Bun.build({
  entrypoints: ["./src/index.ts"],
});

// Multiple entries
await Bun.build({
  entrypoints: [
    "./src/index.ts",
    "./src/worker.ts",
    "./src/admin.ts",
  ],
});

// Glob patterns
await Bun.build({
  entrypoints: ["./src/**/*.entry.ts"],
});
```

## Output

### Directory Output

```typescript
await Bun.build({
  entrypoints: ["./src/index.ts"],
  outdir: "./dist",
});
```

### Single File Output

```typescript
await Bun.build({
  entrypoints: ["./src/index.ts"],
  outfile: "./dist/bundle.js",
});
```

### Naming Patterns

```typescript
await Bun.build({
  entrypoints: ["./src/index.ts"],
  outdir: "./dist",
  naming: {
    entry: "[dir]/[name].[ext]",
    chunk: "chunks/[name]-[hash].[ext]",
    asset: "assets/[name]-[hash].[ext]",
  },
});
```

Placeholders:
- `[name]` - Original filename without extension
- `[ext]` - File extension
- `[hash]` - Content hash
- `[dir]` - Relative directory path

## Minification

```typescript
// Full minification
await Bun.build({
  minify: true,
});

// Selective minification
await Bun.build({
  minify: {
    whitespace: true,
    identifiers: true,
    syntax: true,
  },
});

// Individual flags
await Bun.build({
  minify: {
    whitespace: true,   // Remove whitespace
    identifiers: false, // Keep variable names
    syntax: true,       // Shorten syntax
  },
});
```

## Source Maps

```typescript
// No source map
await Bun.build({
  sourcemap: "none",
});

// Inline (in bundle)
await Bun.build({
  sourcemap: "inline",
});

// External (.map file)
await Bun.build({
  sourcemap: "external",
});

// Linked (reference in bundle, separate file)
await Bun.build({
  sourcemap: "linked",
});
```

## Code Splitting

```typescript
await Bun.build({
  entrypoints: ["./src/a.ts", "./src/b.ts"],
  splitting: true,
  outdir: "./dist",
});
```

Shared modules extracted to chunks automatically.

## Define

Replace identifiers at compile time:

```typescript
await Bun.build({
  define: {
    "process.env.NODE_ENV": JSON.stringify("production"),
    "DEBUG": "false",
    "VERSION": JSON.stringify("1.0.0"),
  },
});
```

## External

Exclude from bundle:

```typescript
// Specific packages
await Bun.build({
  external: ["react", "react-dom"],
});

// All packages
await Bun.build({
  packages: "external",
});

// Patterns
await Bun.build({
  external: ["@company/*"],
});
```

## Loaders

```typescript
await Bun.build({
  loader: {
    ".png": "file",
    ".svg": "text",
    ".graphql": "text",
    ".woff2": "file",
    ".css": "css",
    ".json": "json",
    ".txt": "text",
    ".bin": "base64",
  },
});
```

### Loader Types

| Loader | Output |
|--------|--------|
| `js` | JavaScript |
| `jsx` | JavaScript (JSX) |
| `ts` | JavaScript (TypeScript) |
| `tsx` | JavaScript (TSX) |
| `json` | JavaScript object |
| `toml` | JavaScript object |
| `text` | String export |
| `file` | URL/path to file |
| `base64` | Base64 string |
| `dataurl` | Data URL |
| `css` | CSS file |
| `napi` | Native addon |
| `wasm` | WebAssembly |

## Conditions

Custom export conditions:

```typescript
await Bun.build({
  conditions: ["react-server", "production"],
});
```

## Drop

Remove specific constructs:

```typescript
await Bun.build({
  drop: ["console", "debugger"],
});
```

## Banner/Footer

Add text to output:

```typescript
await Bun.build({
  banner: "/* Copyright 2024 */",
  footer: "// End of bundle",
});
```

## JSX Configuration

```typescript
await Bun.build({
  jsx: "automatic",           // or "classic" | "preserve"
  jsxFactory: "h",            // For classic
  jsxFragment: "Fragment",    // For classic
  jsxImportSource: "preact",  // For automatic
  jsxSideEffects: false,      // Tree-shake JSX
});
```

## Bytecode (Bun target)

Pre-compile to bytecode:

```typescript
await Bun.build({
  target: "bun",
  bytecode: true,
});
```

Faster startup, obfuscated code.
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall