npx skills add https://bun.sh/docsBun 是一个使用 Zig 语言编写的、一体化的 JavaScript/TypeScript 运行时和工具包。它以一个独立的二进制文件形式发布,包含一个运行时(可直接替代 Node.js)、包管理器、测试运行器和打包器。使用 bun run 来执行文件,bun install 来管理依赖,bun test 来运行测试,bun build 来打包代码。主要文档位于 https://bun.com/docs。
关键文件和命令:
bunfig.toml — 配置文件(可选,默认零配置)bun run <file> — 执行 JavaScript/TypeScript 文件,支持原生转译bun install — 安装依赖(比 npm 快 25 倍)bun test — 运行与 Jest 兼容的测试bun build — 为浏览器、服务器或可执行文件打包Bun is an all-in-one JavaScript/TypeScript runtime and toolkit written in Zig. It ships as a single binary and includes a runtime (drop-in Node.js replacement), package manager, test runner, and bundler. Use bun run to execute files, bun install to manage dependencies, bun test to run tests, and bun build to bundle code. The primary documentation is at https://bun.com/docs.
Key files and commands:
bunfig.toml — Configuration file (optional, zero-config by default)bun run <file> — Execute JavaScript/TypeScript files with native transpilationbun install — Install dependencies (25x faster than npm)广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
package.json — 标准的 Node.js 项目文件(完全兼容)在以下情况时使用此技能:
.ts、.tsx、.js、.jsx 文件,无需编译步骤Bun.serve() 或 Express、Elysia、Hono 等框架构建 HTTP 服务器| 任务 | 命令 |
|---|---|
| 运行文件 | bun run index.ts 或 bun index.ts |
| 运行脚本 | bun run dev (来自 package.json) |
| 安装依赖 | bun install |
| 添加包 | bun add react 或 bun add -d typescript |
| 移除包 | bun remove react |
| 运行测试 | bun test |
| 监视模式 | bun --watch run index.ts 或 bun test --watch |
| 构建包 | bun build ./index.ts --outdir ./dist |
| 创建项目 | bun init my-app |
| 扩展名 | 行为 |
|---|---|
.ts, .tsx | TypeScript + JSX,即时转译 |
.js, .jsx | JavaScript + JSX,即时转译 |
.json, .toml, .yaml | 在构建时或运行时解析并内联 |
.html | 全栈打包,包含资源处理 |
.css | 打包并优化 |
./bunfig.toml (项目根目录)$HOME/.bunfig.toml 或 $XDG_CONFIG_HOME/.bunfig.toml[install]
linker = "hoisted" # 或 "isolated" 以实现类似 pnpm 的行为
optional = true
dev = true
production = false
[test]
root = "."
coverage = false
timeout = 5000
[run]
shell = "system" # 在 Windows 上也可以是 "bun"
bun = true # 自动将 node 别名指向 bun
[define]
"process.env.DEBUG" = "'true'"
| 场景 | 使用 | 原因 |
|---|---|---|
| 链接器策略 | hoisted | 传统的 npm 行为,适用于现有项目 |
isolated | 新的工作区,需要严格的依赖隔离 | |
| 包管理器 | bun install | 快 25 倍,API 与 npm 相同 |
npm install | 仅在 Bun 不可用时使用 | |
| 测试运行器 | bun test | 与 Jest 兼容,原生支持 TypeScript,速度快 |
jest | 仅在 Bun 不兼容时使用 | |
| 打包器 | bun build | 原生,速度快,能处理全栈应用 |
esbuild | 仅在 Bun 不可用时使用 | |
| 运行时 | bun run | 启动速度比 Node.js 快 4 倍 |
node | 仅在 Bun 不可用时使用 | |
| 服务器 | Bun.serve() | 原生,高性能,内置路由 |
| Express/Hono | 当你需要框架特性时 |
bun init my-app
cd my-app
这将创建 package.json、tsconfig.json、bunfig.toml 和一个起始 index.ts 文件。
bun install
bun add react
bun add -d @types/react
Bun 读取 package.json,解析依赖,并创建 bun.lock(基于文本的锁文件)。
创建 index.ts:
const server = Bun.serve({
port: 3000,
routes: {
"/": () => new Response("Hello!"),
},
});
console.log(`Listening on ${server.url}`);
运行它:
bun run index.ts
# 或
bun index.ts
{
"scripts": {
"dev": "bun --watch run index.ts",
"build": "bun build ./index.ts --outdir ./dist",
"test": "bun test"
}
}
运行:
bun run dev
bun run build
bun run test
创建 math.test.ts:
import { test, expect } from "bun:test";
test("2 + 2 = 4", () => {
expect(2 + 2).toBe(4);
});
运行测试:
bun test
bun test --watch
bun test --coverage
bun build ./index.ts --outdir ./dist --minify
对于可执行文件:
bun build ./cli.ts --outfile ./mycli --compile
./mycli
bun testbun run tsc --noEmitbun build ./index.ts --outdir ./distnode ./dist/index.jspackage.json 的 trustedDependencies 中以允许 postinstall 脚本。bunfig.toml 中设置 [install] auto = "disable" 来尽早发现缺失的包。bun之后,而不是脚本之后:使用 bun --watch run dev,而不是 bun run dev --watch。*.test.ts、*_test.ts、*.spec.ts、*_spec.ts 会被自动发现。bun.lock 而不是二进制的 bun.lockb。使用 bun install --save-text-lockfile 进行升级。bunfig.toml 中切换到 linker = "hoisted"。$VAR_NAME 语法;Bun 会自动加载 .env、.env.local、.env.[NODE_ENV]。tsc --noEmit 单独进行类型检查;bun build 只进行转译。bun build --target=bun 或 bun --hot:它们不能直接与 bun run 一起工作。在使用 Bun 提交工作之前:
bun run index.tsbun testbun run tsc --noEmitbun install 完成且无错误bun.lock 在版本控制中bun build ./index.ts --outdir ./dist 完成bun --watch run dev如需更多文档和导航,请参阅:https://bun.com/docs/llms.txt
每周安装量
209
来源
首次出现
2026年3月2日
安全审计
安装于
opencode207
gemini-cli206
kimi-cli206
codex206
cursor206
amp206
bun test — Run Jest-compatible testsbun build — Bundle for browsers, servers, or executablespackage.json — Standard Node.js project file (fully compatible)Reach for this skill when:
.ts, .tsx, .js, .jsx files directly without compilation stepsBun.serve() or frameworks like Express, Elysia, Hono| Task | Command |
|---|---|
| Run a file | bun run index.ts or bun index.ts |
| Run a script | bun run dev (from package.json) |
| Install dependencies | bun install |
| Add a package | bun add react or bun add -d typescript |
| Remove a package | bun remove react |
| Run tests | bun test |
| Watch mode | bun --watch run index.ts or bun test --watch |
| Build a bundle | bun build ./index.ts --outdir ./dist |
| Create a project | bun init my-app |
| Extension | Behavior |
|---|---|
.ts, .tsx | TypeScript + JSX, transpiled on-the-fly |
.js, .jsx | JavaScript + JSX, transpiled on-the-fly |
.json, .toml, .yaml | Parsed and inlined at build time or runtime |
.html | Full-stack bundling with asset processing |
.css | Bundled and optimized |
./bunfig.toml (project root)$HOME/.bunfig.toml or $XDG_CONFIG_HOME/.bunfig.toml[install]
linker = "hoisted" # or "isolated" for pnpm-like behavior
optional = true
dev = true
production = false
[test]
root = "."
coverage = false
timeout = 5000
[run]
shell = "system" # or "bun" on Windows
bun = true # auto-alias node to bun
[define]
"process.env.DEBUG" = "'true'"
| Scenario | Use | Why |
|---|---|---|
| Linker strategy | hoisted | Traditional npm behavior, existing projects |
isolated | New workspaces, strict dependency isolation | |
| Package manager | bun install | 25x faster, same API as npm |
npm install | Only if Bun not available | |
| Test runner | bun test | Jest-compatible, TypeScript native, fast |
jest | Only if Bun incompatible | |
| Bundler | bun build | Native, fast, handles full-stack apps |
esbuild | Only if Bun not available | |
| Runtime | bun run | 4x faster startup than Node.js |
node | Only if Bun not available | |
| Server | Bun.serve() | Native, high-performance, built-in routing |
| Express/Hono | When you need framework features |
bun init my-app
cd my-app
This creates package.json, tsconfig.json, bunfig.toml, and a starter index.ts.
bun install
bun add react
bun add -d @types/react
Bun reads package.json, resolves dependencies, and creates bun.lock (text-based lockfile).
Create index.ts:
const server = Bun.serve({
port: 3000,
routes: {
"/": () => new Response("Hello!"),
},
});
console.log(`Listening on ${server.url}`);
Run it:
bun run index.ts
# or
bun index.ts
{
"scripts": {
"dev": "bun --watch run index.ts",
"build": "bun build ./index.ts --outdir ./dist",
"test": "bun test"
}
}
Run with:
bun run dev
bun run build
bun run test
Create math.test.ts:
import { test, expect } from "bun:test";
test("2 + 2 = 4", () => {
expect(2 + 2).toBe(4);
});
Run tests:
bun test
bun test --watch
bun test --coverage
bun build ./index.ts --outdir ./dist --minify
For executables:
bun build ./cli.ts --outfile ./mycli --compile
./mycli
bun testbun run tsc --noEmit (if using TypeScript)bun build ./index.ts --outdir ./distnode ./dist/index.jstrustedDependencies in package.json to allow postinstall scripts.[install] auto = "disable" in bunfig.toml to catch missing packages early.bun, not after the script: Use bun --watch run dev, not bun run dev --watch.*.test.ts, *_test.ts, *.spec.ts, *_spec.ts are discovered automatically.bun.lock instead of binary bun.lockb. Upgrade with bun install --save-text-lockfile.linker = "hoisted" in bunfig.toml.$VAR_NAME syntax; Bun loads .env, .env.local, .env.[NODE_ENV] automatically.tsc --noEmit separately for type checking; bun build only transpiles.bun build --target=bun or bun --hot: They don't work with bun run directly.Before submitting work with Bun:
bun run index.tsbun testbun run tsc --noEmitbun install completes without errorsbun.lock is in version controlbun build ./index.ts --outdir ./dist completesbun --watch run devFor additional documentation and navigation, see: https://bun.com/docs/llms.txt
Weekly Installs
209
Source
First Seen
Mar 2, 2026
Security Audits
Installed on
opencode207
gemini-cli206
kimi-cli206
codex206
cursor206
amp206
Node.js 环境配置指南:多环境管理、类型安全与最佳实践
10,500 周安装
Loom视频转录获取器 - 自动提取Loom视频字幕与文本,支持GraphQL API
163 周安装
bioRxiv数据库Python工具:高效搜索下载预印本,支持关键词/作者/日期/类别筛选
163 周安装
Magento 2 Hyvä CMS 组件创建器 - 快速构建自定义CMS组件
163 周安装
项目文档协调器 - 自动化文档生成与上下文管理工具
163 周安装
GPUI 布局与样式:Rust 类型安全的 CSS 样式库,Flexbox 布局与链式 API
163 周安装
Telegram自动化指南:通过Rube MCP与Composio实现消息发送、聊天管理
163 周安装