# Bun Setup & Usage Guide **For:** ThrillWiki Next.js 15 Migration **Last Updated:** November 9, 2025 --- ## ๐ŸŽฏ Overview Bun is an all-in-one JavaScript runtime & toolkit that replaces Node.js, npm, yarn, and webpack. It's significantly faster than traditional tools and is the official package manager for this migration. **Why Bun?** - โšก 25x faster than npm - ๐Ÿš€ Fast startup times - ๐Ÿ“ฆ All-in-one (runtime + bundler + package manager) - ๐Ÿ”„ Drop-in replacement for Node.js/npm - โœ… Compatible with Next.js 15 --- ## ๐Ÿ“ฅ Installation ### macOS & Linux ```bash curl -fsSL https://bun.sh/install | bash ``` ### Windows (WSL2) ```bash curl -fsSL https://bun.sh/install | bash ``` ### Verify Installation ```bash bun --version # Should output: 1.x.x ``` --- ## ๐Ÿš€ Basic Commands ### Package Management ```bash # Install dependencies from package.json bun install # Install a specific package bun add # Install as dev dependency bun add -d # Install globally bun add -g # Remove a package bun remove # Update packages bun update # Update a specific package bun update ``` ### Running Scripts ```bash # Run a package.json script bun run dev bun run build bun run start bun run test # Or shorter (bun run is optional) bun dev bun build bun start bun test ``` ### Running Files ```bash # Run a TypeScript/JavaScript file directly bun index.ts bun server.js # Run with watch mode (auto-restart on changes) bun --watch index.ts ``` --- ## ๐Ÿ“ฆ Common ThrillWiki Commands ### Development ```bash # Start Next.js development server with Turbopack bun run dev # Or shorter bun dev # Expected output: # โ–ฒ Next.js 15.x.x # - Local: http://localhost:3000 # - Turbopack: โœ“ Enabled ``` ### Building ```bash # Create production build bun run build # This will: # 1. Compile TypeScript # 2. Build Next.js pages # 3. Optimize bundles # 4. Generate static pages (ISR/SSG) ``` ### Production ```bash # Start production server (after build) bun run start # Server will run on http://localhost:3000 ``` ### Type Checking ```bash # Run TypeScript compiler bun run type-check # This runs: tsc --noEmit ``` ### Linting ```bash # Run ESLint bun run lint # Fix auto-fixable issues bun run lint --fix ``` ### Testing ```bash # Run tests bun test # Run tests in watch mode bun test --watch # Run tests with coverage bun test --coverage ``` --- ## ๐Ÿ”ง Project Setup ### Initialize New Next.js Project ```bash # Create new Next.js 15 project with Bun bun create next-app@latest my-project --typescript --tailwind --app cd my-project ``` ### Migrate Existing Project to Bun ```bash # Remove old lock files rm package-lock.json rm yarn.lock rm pnpm-lock.yaml # Install with Bun bun install # This creates bun.lockb ``` --- ## โš™๏ธ Configuration ### package.json Scripts Update your `package.json` scripts to use Bun: ```json { "scripts": { "dev": "next dev --turbo", "build": "next build", "start": "next start", "lint": "next lint", "type-check": "tsc --noEmit", "test": "vitest" } } ``` ### .bunfig.toml (Optional) Create `.bunfig.toml` in project root for Bun configuration: ```toml # Bun configuration [install] # Use exact versions (like npm's --exact) exact = true # Cache directory cache = ".bun-cache" # Optional: Configure registry # registry = "https://registry.npmjs.org" [test] # Test configuration coverage = true ``` --- ## ๐Ÿ”„ NPM to Bun Command Mapping | NPM Command | Bun Command | Description | |------------|-------------|-------------| | `npm install` | `bun install` | Install dependencies | | `npm install ` | `bun add ` | Add package | | `npm install -D ` | `bun add -d ` | Add dev dependency | | `npm uninstall ` | `bun remove ` | Remove package | | `npm run