オプション

bun-runtime

affaan-m/ECC affaan-m/ECC

BunをJavaScriptランタイム、パッケージマネージャー、バンドラー、テストランナーとして使用する方法について解説しています。これには、Node.jsからの移行やVercelへのデプロイについても含まれます。

...すべて拡張します
0
更新された時間 2026年10月1日

Bun Runtime

Bunは、高速なオールインワンJavaScriptランタイムおよびツールキットです。ランタイム、パッケージマネージャー、バンドラー、テストランナーの機能を兼ね備えています。

使用すべき場面

  • Bun を推奨するケース:新しい JS/TS プロジェクト、インストールや実行の速度が重要なスクリプト、Bun ランタイムを使用した Vercel へのデプロイ、および単一のツールチェーン(実行 + インストール + テスト + ビルド)を望む場合。
  • Node を推奨するケース:エコシステムとの互換性を最大限に確保したい場合、Node を前提とするレガシーツールを使用する場合、または依存関係に Bun に関する既知の問題がある場合。

以下の場合に使用してください:Bunの導入、Nodeからの移行、Bunスクリプトやテストの作成・デバッグ、Vercelやその他のプラットフォームでのBunの設定。

仕組み

  • ランタイム:Nodeと互換性のあるドロップイン型ランタイム(JavaScriptCoreを基盤とし、Zigで実装)。
  • パッケージマネージャー: bun install npm/yarnよりも大幅に高速です。ロックファイルは bun.lock 現在のBunではデフォルトで(テキスト形式)です。以前のバージョンでは bun.lockb (バイナリ) 形式でした。
  • バンドラー:アプリやライブラリ用の組み込みバンドラーおよびトランスパイラー。
  • テストランナー: bun test Jest風のAPIを備えています。

Node からの移行: node script.js を bun run script.js または bun script.jsに置き換えてください。 bun install を実行してください npm installを実行してください。ほとんどのパッケージは動作します。npmスクリプトの場合は bun run を使用してください。 bun x npx スタイルの単発実行には `npx` を使用してください。Node の組み込み関数はサポートされていますが、パフォーマンス向上のため、Bun API が利用可能な場合はそちらを優先してください。

Vercel:プロジェクト設定でランタイムを Bun に設定してください。ビルド: bun run build または bun build ./src/index.ts --outdir=dist。インストール: bun install --frozen-lockfile 再現性のあるデプロイを行う場合。

例

実行およびインストール

# Install dependencies (creates/updates bun.lock or bun.lockb)
bun install

# Run a script or file
bun run dev
bun run src/index.ts
bun src/index.ts

スクリプトと環境

bun run --env-file=.env dev
FOO=bar bun run script.ts

テスト

bun test
bun test --watch
// test/example.test.ts
import { expect, test } from "bun:test";

test("add", () => {
  expect(1 + 2).toBe(3);
});

ランタイム API

const file = Bun.file("package.json");
const json = await file.json();

Bun.serve({
  port: 3000,
  fetch(req) {
    return new Response("Hello");
  },
});

ベストプラクティス

  • ロックファイルをコミットする (bun.lock または bun.lockb)をコミットして、再現性のあるインストールを実現してください。
  • スクリプトには bun run を使用することを推奨します。TypeScriptの場合、Bunは .ts ネイティブで実行されます。
  • 依存関係は常に最新の状態に保ってください。Bunとそのエコシステムは急速に進化しています。
GitHubで見る
---
name: bun-runtime
description: Provides guidance on using Bun as a JavaScript runtime, package manager, bundler, and test runner, including migration from Node.js and Vercel deployment.
---

# Bun Runtime

Bun is a fast all-in-one JavaScript runtime and toolkit: runtime, package manager, bundler, and test runner.

## When to Use

- **Prefer Bun** for: new JS/TS projects, scripts where install/run speed matters, Vercel deployments with Bun runtime, and when you want a single toolchain (run + install + test + build).
- **Prefer Node** for: maximum ecosystem compatibility, legacy tooling that assumes Node, or when a dependency has known Bun issues.

Use when: adopting Bun, migrating from Node, writing or debugging Bun scripts/tests, or configuring Bun on Vercel or other platforms.

## How It Works

- **Runtime**: Drop-in Node-compatible runtime (built on JavaScriptCore, implemented in Zig).
- **Package manager**: `bun install` is significantly faster than npm/yarn. Lockfile is `bun.lock` (text) by default in current Bun; older versions used `bun.lockb` (binary).
- **Bundler**: Built-in bundler and transpiler for apps and libraries.
- **Test runner**: Built-in `bun test` with Jest-like API.

**Migration from Node**: Replace `node script.js` with `bun run script.js` or `bun script.js`. Run `bun install` in place of `npm install`; most packages work. Use `bun run` for npm scripts; `bun x` for npx-style one-off runs. Node built-ins are supported; prefer Bun APIs where they exist for better performance.

**Vercel**: Set runtime to Bun in project settings. Build: `bun run build` or `bun build ./src/index.ts --outdir=dist`. Install: `bun install --frozen-lockfile` for reproducible deploys.

## Examples

### Run and install

```bash
# Install dependencies (creates/updates bun.lock or bun.lockb)
bun install

# Run a script or file
bun run dev
bun run src/index.ts
bun src/index.ts
```

### Scripts and env

```bash
bun run --env-file=.env dev
FOO=bar bun run script.ts
```

### Testing

```bash
bun test
bun test --watch
```

```typescript
// test/example.test.ts
import { expect, test } from "bun:test";

test("add", () => {
  expect(1 + 2).toBe(3);
});
```

### Runtime API

```typescript
const file = Bun.file("package.json");
const json = await file.json();

Bun.serve({
  port: 3000,
  fetch(req) {
    return new Response("Hello");
  },
});
```

## Best Practices

- Commit the lockfile (`bun.lock` or `bun.lockb`) for reproducible installs.
- Prefer `bun run` for scripts. For TypeScript, Bun runs `.ts` natively.
- Keep dependencies up to date; Bun and the ecosystem evolve quickly.

すべてのファイル

1件のファイル

bun-runtimeをインストール

スキルファイルをダウンロードし、.claude/skills/ ディレクトリに解凍してください。

ZIPをダウンロード

リポジトリをクローンし、スキルファイルをプロジェクトにコピーしてください。

git clone https://github.com/affaan-m/ECC/tree/main/skills/bun-runtime # Copy SKILL.md to your .claude/skills/ directory

コピー コピー
クイックセットアップ: スキルフォルダを .claude/skills/ にコピーしてください。 Claude が自動的にそのスキルを検出して使用します。
リポジトリ affaan-m/ECC

関連スキル

algorithmic-art
更新された時間 2026年8月27日
systematic-debugging
更新された時間 2026年9月3日
tech-debt-tracker
更新された時間 2026年8月29日
continual-learning
更新された時間 2026年9月10日
OR