一键导入
bun-init
Initialize a new Bun project with TypeScript and optimal configuration. Use when starting a new Bun project or converting a directory to a Bun project.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Initialize a new Bun project with TypeScript and optimal configuration. Use when starting a new Bun project or converting a directory to a Bun project.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Converts Stitch designs into modular Vite and React components using system-level networking and AST-based validation.
Generate walkthrough videos from Stitch projects using Remotion with smooth transitions, zooming, and text overlays
Expert guidance for integrating and building applications with shadcn/ui components, including component discovery, installation, customization, and best practices.
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
Converts Stitch designs into modular Vite and React components using system-level networking and AST-based validation.
Generate walkthrough videos from Stitch projects using Remotion with smooth transitions, zooming, and text overlays
| name | bun-init |
| description | Initialize a new Bun project with TypeScript and optimal configuration. Use when starting a new Bun project or converting a directory to a Bun project. |
| compatibility | Requires Bun 1.0+ |
| allowed-tools | ["Bash","Write","Read"] |
| metadata | {"author":"dale","category":"bun-runtime","tags":["bun","javascript","typescript","initialization","setup"]} |
You are assisting with initializing a new Bun project. Follow these steps to create a well-structured project with optimal configurations.
First, verify Bun is installed:
bun --version
If Bun is not installed, provide installation instructions for the user's platform.
Ask the user which type of project they want to create:
Execute the initialization command:
bun init -y
This creates:
package.json with Bun-optimized scriptstsconfig.json with recommended TypeScript settingsindex.ts as the entry pointREADME.md with basic project infoRead the generated tsconfig.json and enhance it based on project type:
For CLI Tools:
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"types": ["bun-types"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"allowImportingTsExtensions": true,
"noEmit": true
}
}
For Web Apps:
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"module": "ESNext",
"moduleResolution": "bundler",
"jsx": "react-jsx",
"types": ["bun-types"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"allowImportingTsExtensions": true,
"noEmit": true
}
}
For API Servers:
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"types": ["bun-types"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"allowImportingTsExtensions": true,
"noEmit": true,
"paths": {
"@/*": ["./src/*"]
}
}
}
For Libraries:
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"types": ["bun-types"],
"strict": true,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"allowImportingTsExtensions": true,
"noEmit": true
}
}
Generate appropriate directory structure and files:
CLI Tool:
project/
├── src/
│ ├── index.ts # Main CLI entry point
│ ├── commands/ # Command handlers
│ └── utils/ # Shared utilities
├── tests/
│ └── index.test.ts
├── package.json
├── tsconfig.json
├── .gitignore
├── .env.example
└── README.md
Create src/index.ts:
#!/usr/bin/env bun
console.log("Hello from Bun CLI!");
// Example: Parse command line arguments
const args = process.argv.slice(2);
console.log("Arguments:", args);
Update package.json to add bin field:
{
"bin": {
"your-cli-name": "./src/index.ts"
}
}
Web App:
project/
├── src/
│ ├── index.tsx # App entry point
│ ├── components/ # React components
│ ├── styles/ # CSS/styles
│ └── utils/ # Utilities
├── public/
│ └── index.html
├── tests/
├── package.json
├── tsconfig.json
├── .gitignore
├── .env.example
└── README.md
API Server:
project/
├── src/
│ ├── index.ts # Server entry point
│ ├── routes/ # Route handlers
│ ├── middleware/ # Express/Hono middleware
│ ├── services/ # Business logic
│ └── types/ # TypeScript types
├── tests/
├── package.json
├── tsconfig.json
├── .gitignore
├── .env.example
└── README.md
Create src/index.ts:
const server = Bun.serve({
port: 3000,
fetch(request) {
return new Response("Welcome to Bun!");
},
});
console.log(`Server running at http://localhost:${server.port}`);
Library:
project/
├── src/
│ ├── index.ts # Main export
│ └── types.ts # Type definitions
├── tests/
├── package.json
├── tsconfig.json
├── .gitignore
└── README.md
Generate a comprehensive .gitignore:
# Bun
node_modules
bun.lockb
*.bun
# Environment
.env
.env.local
.env.*.local
# Build outputs
dist/
build/
*.tsbuildinfo
# Logs
logs
*.log
npm-debug.log*
# OS
.DS_Store
Thumbs.db
# IDE
.vscode/
.idea/
*.swp
*.swo
*~
# Test coverage
coverage/
.nyc_output/
Create .env.example:
# Application
NODE_ENV=development
PORT=3000
# Add your environment variables here
# DATABASE_URL=
# API_KEY=
Add project-type-specific scripts:
CLI Tool:
{
"scripts": {
"dev": "bun run src/index.ts",
"test": "bun test",
"lint": "bun run --bun eslint src",
"typecheck": "bun run --bun tsc --noEmit"
}
}
Web App:
{
"scripts": {
"dev": "bun run --hot src/index.tsx",
"build": "bun build src/index.tsx --outdir=dist --minify",
"test": "bun test",
"typecheck": "bun run --bun tsc --noEmit"
}
}
API Server:
{
"scripts": {
"dev": "bun run --hot src/index.ts",
"start": "bun run src/index.ts",
"test": "bun test",
"typecheck": "bun run --bun tsc --noEmit"
}
}
Library:
{
"scripts": {
"build": "bun build src/index.ts --outdir=dist --minify --sourcemap=external",
"test": "bun test",
"typecheck": "bun run --bun tsc --noEmit",
"prepublishOnly": "bun run build && bun test"
}
}
Suggest installing common dependencies based on project type:
CLI Tool:
bun add commander chalk ora
bun add -d @types/node
Web App:
bun add react react-dom
bun add -d @types/react @types/react-dom
API Server:
bun add hono
bun add -d @types/node
Library:
# No default dependencies - user will add as needed
Create a basic test file in tests/:
import { describe, expect, test } from "bun:test";
describe("Initial test", () => {
test("basic assertion", () => {
expect(1 + 1).toBe(2);
});
});
After completing the setup, provide the user with:
.env.example to .env and configurebun install if dependencies were suggestedbun dev to start developmentbun test to verify tests work"moduleResolution": "bundler" for Bun's native resolution"types": ["bun-types"]"noEmit": true since Bun runs TypeScript directly"allowImportingTsExtensions": true for .ts importsIf user wants workspaces (monorepo):
Add to package.json:
{
"workspaces": ["packages/*"]
}
If user wants path aliases:
Add to tsconfig.json:
{
"compilerOptions": {
"paths": {
"@/*": ["./src/*"],
"@components/*": ["./src/components/*"]
}
}
}
If user wants JSX without React:
Update tsconfig.json:
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact" // or other JSX runtime
}
}
Once all files are created, inform the user that initialization is complete and provide a summary of: