New advertisers: 50% off your first month with code FIRSTMONTHSee slots

Comprehensive Bun runtime toolkit covering runtime, package manager, bundler, testing, HTTP servers, WebSockets, databases, framework integrations (Hono, Next.js, Nuxt, TanStack Start, SvelteKit), deployment, and Node.js compatibility.

version
3.12.0
GitHub stars
250
View on GitHub

Add marketplace

/plugin marketplace add secondsky/claude-skills

Run it inside Claude Code once, then install the plugin below.

Install

/plugin install bun@claude-skills

Run it inside Claude Code after adding the marketplace.

Files

Discovered from source

Bun Bundler

Bun's bundler is a fast JavaScript/TypeScript bundler built on the same engine as Bun's runtime. It's an esbuild-compatible alternative with native performance.

Quick Start

CLI

# Basic bundle
bun build ./src/index.ts --outdir ./dist

# Production build
bun build ./src/index.ts --outdir ./dist --minify

# Multiple entry points
bun build ./src/index.ts ./src/worker.ts --outdir ./dist

JavaScript API

// Since Bun 1.2, Bun.build REJECTS on failure (throws).
// Wrap in try/catch to handle errors; pass { throw: false } to restore the
// old resolve-with-{ success, logs } contract if you prefer that style.
try {
  const result = await Bun.build({
    entrypoints: ["./src/index.ts"],
    outdir: "./dist",
  });
  console.log(`Built ${result.outputs.length} files`);
} catch (err) {
  console.error("Build failed:", err);
  process.exit(1);
}

Bun.build Options

await Bun.build({
  // Entry points (required)
  entrypoints: ["./src/index.ts"],

  // Output directory
  outdir: "./dist",

  // Target environment
  target: "browser",  // "browser" | "bun" | "node"

  // Output format
  format: "esm",  // "esm" | "cjs" | "iife"

  // Minification
  minify: true,  // or { whitespace: true, identifiers: true, syntax: true }

  // Code splitting
  splitting: true,

  // Source maps
  sourcemap: "external",  // "none" | "inline" | "external" | "linked"

  // Naming patterns
  naming: {
    entry: "[dir]/[name].[ext]",
    chunk: "[name]-[hash].[ext]",
    asset: "[name]-[hash].[ext]",
  },

  // Define globals
  define: {
    "process.env.NODE_ENV": JSON.stringify("production"),
  },

  // External packages
  external: ["react", "react-dom"],

  // Loaders
  loader: {
    ".svg": "text",
    ".png": "file",
  },

  // Plugins
  plugins: [myPlugin],

  // Root directory
  root: "./src",

  // Public path for assets
  publicPath: "/static/",
});

CLI Flags

bun build <entrypoints> [flags]
FlagDescription
--outdirOutput directory
--outfileOutput single file
--targetbrowser, bun, node
--formatesm, cjs, iife
--minifyEnable minification
--minify-whitespaceMinify whitespace only
--minify-identifiersMinify identifiers only
--minify-syntaxMinify syntax only
--splittingEnable code splitting
--sourcemapnone, inline, external, linked
--externalMark packages as external
--defineDefine compile-time constants
--loaderCustom loaders for extensions
--public-pathPublic path for assets
--rootRoot directory
--entry-namingEntry point naming pattern
--chunk-namingChunk naming pattern
--asset-namingAsset naming pattern

Target Environments

Browser (default)

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

Bun Runtime

await Bun.build({
  entrypoints: ["./src/server.ts"],
  target: "bun",
  outdir: "./dist",
});

Node.js

await Bun.build({
  entrypoints: ["./src/server.ts"],
  target: "node",
  outdir: "./dist",
});

Code Splitting

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

Shared dependencies are extracted into separate chunks automatically.

Loaders

LoaderExtensionsOutput
js.js, .mjs, .cjsJavaScript
jsx.jsxJavaScript
ts.ts, .mts, .ctsJavaScript
tsx.tsxJavaScript
json.jsonJavaScript
toml.tomlJavaScript
text-String export
file-File path export
base64-Base64 string
dataurl-Data URL
css.cssCSS file

Custom loaders:

await Bun.build({
  entrypoints: ["./src/index.ts"],
  loader: {
    ".svg": "text",
    ".png": "file",
    ".woff2": "file",
  },
});

Plugins

const myPlugin = {
  name: "my-plugin",
  setup(build) {
    // Resolve hook
    build.onResolve({ filter: /\.special$/ }, (args) => {
      return { path: args.path, namespace: "special" };
    });

    // Load hook
    build.onLoad({ filter: /.*/, namespace: "special" }, (args) => {
      return {
        contents: `export default "special"`,
        loader: "js",
      };
    });
  },
};

await Bun.build({
  entrypoints: ["./src/index.ts"],
  plugins: [myPlugin],
});

Build Output

// Bun 1.2+: Bun.build rejects on failure. Use try/catch to surface build
// errors (or pass { throw: false } and keep the legacy { success, logs } shape).
try {
  const result = await Bun.build({
    entrypoints: ["./src/index.ts"],
    outdir: "./dist",
  });

  // Access outputs
  for (const output of result.outputs) {
    console.log(output.path);   // File path
    console.log(output.kind);   // "entry-point" | "chunk" | "asset"
    console.log(output.hash);   // Content hash
    console.log(output.loader); // Loader used

    // Read content
    const text = await output.text();
  }
} catch (err) {
  console.error("Build failed:", err);
  process.exit(1);
}

Common Patterns

Production Build

await Bun.build({
  entrypoints: ["./src/index.ts"],
  outdir: "./dist",
  target: "browser",
  minify: true,
  sourcemap: "external",
  splitting: true,
  define: {
    "process.env.NODE_ENV": JSON.stringify("production"),
  },
});

Library Build

await Bun.build({
  entrypoints: ["./src/index.ts"],
  outdir: "./dist",
  target: "bun",
  format: "esm",
  external: ["*"],  // Externalize all dependencies
  sourcemap: "external",
});

Build Script

// build.ts
// Bun 1.2+: Bun.build rejects on failure, so try/catch is the modern idiom.
try {
  const result = await Bun.build({
    entrypoints: ["./src/index.ts"],
    outdir: "./dist",
    minify: process.env.NODE_ENV === "production",
  });
  console.log(`Built ${result.outputs.length} files`);
} catch (err) {
  console.error("Build failed:", err);
  process.exit(1);
}

Run: bun run build.ts

Common Errors

ErrorCauseFix
Could not resolveMissing importInstall package or fix path
No matching exportNamed export missingCheck export name
Unexpected tokenSyntax errorFix source code
Target not supportedInvalid targetUse browser, bun, or node

When to Load References

Load references/options.md when:

  • Need complete option reference
  • Configuring advanced features

Load references/plugins.md when:

  • Writing custom plugins
  • Understanding plugin API

Load references/macros.md when:

  • Using compile-time macros
  • Build-time code generation

Readme

Bun Plugin for Claude Code

Comprehensive Claude Code plugin for the Bun JavaScript runtime. Covers runtime, package manager, bundler, testing, servers, databases, frameworks, and deployment.

Installation

/plugin install bun@claude-skills

Features

27 Skills

Core (3 skills)

  • bun-runtime - Runtime execution, CLI, environment, module resolution
  • bun-package-manager - Dependencies, workspaces, lockfiles, migrations
  • bun-bundler - Code bundling, tree shaking, code splitting

Testing (5 skills)

  • bun-test-basics - Writing tests, assertions, describe/it blocks
  • bun-test-mocking - Mock functions, spyOn, module mocking
  • bun-test-lifecycle - beforeAll, afterAll, setup/teardown
  • bun-test-coverage - Code coverage reports, thresholds, CI integration
  • bun-jest-migration - Migrate Jest tests to Bun

Servers & APIs (3 skills)

  • bun-http-server - Bun.serve(), request handling, routing
  • bun-websocket-server - WebSocket connections, pub/sub, broadcasting
  • bun-hono-integration - Hono framework, middleware, RPC

Databases (4 skills)

  • bun-sqlite - Built-in SQLite, prepared statements, transactions
  • bun-drizzle-integration - Drizzle ORM, schema, migrations
  • bun-redis - Redis caching, pub/sub, ioredis/Upstash
  • bun-file-io - File operations, Bun.file(), streaming

Frameworks (6 skills)

  • bun-nextjs - Next.js with Bun runtime
  • bun-nuxt - Nuxt 3 with Bun preset
  • bun-sveltekit - SvelteKit with svelte-adapter-bun
  • bun-tanstack-start - TanStack Start full-stack React
  • bun-react-ssr - Custom React SSR without frameworks
  • bun-hot-reloading - --watch, --hot, HMR

Advanced (4 skills)

  • bun-macros - Compile-time code execution
  • bun-ffi - Foreign function interface for native code
  • bun-workers - Web Workers, worker_threads
  • bun-shell - Bun.$, shell scripting, subprocess

Deployment (2 skills)

  • bun-cloudflare-workers - Deploy to Cloudflare Workers
  • bun-docker - Docker containers with oven/bun images

6 Commands

CommandDescription
/bun-initInitialize new Bun project with optional framework
/bun-migrateMigrate from Node.js/npm to Bun
/bun-debugDebug runtime, test, or build issues
/bun-optimizeOptimize performance and bundle size
/bun-deployDeploy to Docker, Cloudflare, Vercel, etc.
/bun-upgradeUpgrade Bun runtime and dependencies

3 Agents

AgentPurpose
bun-troubleshooterDiagnose and fix errors, crashes, failures
bun-performance-analyzerProfile and optimize performance
bun-migration-assistantMigrate from Node.js/Jest to Bun

2 Hooks

PreToolUse (validate-bun-command.sh)

  • Suggests Bun equivalents for npm/yarn/pnpm commands
  • Warns about deprecated patterns

PostToolUse (bun-suggestions.sh)

  • Provides tips after bun install, test, build
  • Suggests fixes for common errors

Usage Examples

Start a New Project

/bun-init my-app hono

Migrate from npm

/bun-migrate npm

Debug Issues

Ask: "My Bun server keeps crashing" - triggers bun-troubleshooter agent

Optimize Performance

/bun-optimize bundle

Deploy

/bun-deploy docker

Skill Triggers

Skills trigger automatically based on context:

  • "How do I write tests in Bun?" → bun-test-basics
  • "Help me set up Drizzle ORM" → bun-drizzle-integration
  • "I want to build a WebSocket server" → bun-websocket-server
  • "Deploy my app to Cloudflare Workers" → bun-cloudflare-workers

Requirements

  • Bun 1.0+ installed
  • Claude Code CLI

License

MIT

Links

Details

Marketplace
secondsky/claude-skills
Source
plugins/bun
Category
Tooling
Keywords
bun, tooling, workflow, http, sveltekit, tanstack, websockets
Listed since
Apr 7, 2026

More from secondsky/claude-skills

All 122

Similar to bun

More Developer Tools