用途
Bun Development 是一个围绕 Bun 运行时的开发工作流技能,聚焦于运行脚本、测试、构建和初始化项目,并提供面向智能体优化的命令行参数。
该技能适合在以下场景使用:使用 Bun 运行时运行脚本;使用 bun test 运行测试;使用 Bun 进行打包/构建;初始化新的 Bun 项目;编译为独立可执行文件。
以下场景不建议使用本技能:安装和管理依赖请使用 bun-package-manager;发布包到 npm 请使用 bun-publishing;调试 TypeScript/JS 代码请使用 typescript-debugging。对于需要快速单次调用的测试运行和构建,资料中分别列出了 bun-test 和 bun-build 作为替代选项。
主要能力
资料称 Bun 是一体化 JavaScript 运行时,具有以下特点:约 6ms 启动(对比 npm 约 170ms)、原生 TypeScript 执行、内置测试运行器、带有 compile-to-exe 的快速打包器。
技能覆盖四类主要操作:运行脚本、测试、构建、项目初始化。
使用方式
运行脚本
- 运行 package.json 脚本:
bun run <script> - 直接运行文件:
bun <file.ts> - 静默模式(不输出脚本回显):
bun run --silent <script> - 监听模式(变更自动重启):
bun --watch run dev - 热重载(保留状态):
bun --hot run dev - 工作区脚本:在匹配的工作区运行
bun run --filter 'package-*' build;在所有工作区运行bun run --workspaces test;限制每个工作区输出bun run --filter '*' --elide-lines=5 build - 执行包(类似 npx):
bunx <package>;指定版本bunx typescript@5.0 --help;当二进制名与包名不同时bunx -p @angular/cli ng new app;强制使用 Bun 运行时bunx --bun vite dev
测试
- 运行全部测试:
bun test - 运行指定文件:
bun test tests/auth.test.ts - 按名称过滤:
bun test -t \"login\" - 紧凑输出(智能体场景):
bun test --dots - 快速失败:
bun test --bail或bun test --bail=3(3 次失败后停止);组合使用bun test --dots --bail=1 - CI/CD 输出:JUnit XML
bun test --reporter=junit --reporter-outfile=junit.xml;在 CI 中 GitHub Actions 会被自动检测并自动生成注解(仅bun test) - 覆盖率:
bun test --coverage;LCOV 格式bun test --coverage --coverage-reporter=lcov - 测试配置:自定义超时
bun test --timeout=10000;并发运行bun test --concurrent;限制并发bun test --max-concurrency=5;检测不稳定测试bun test --rerun-each=3
构建
- 基础打包:
bun build ./src/index.ts --outdir=dist - 生产构建:
bun build ./src/index.ts --outdir=dist --minify --sourcemap=external - 监听模式:
bun build ./src/index.ts --outdir=dist --watch - 构建目标:浏览器(默认)
--target=browser;Bun 运行时--target=bun;Node.js--target=node - 编译为可执行文件:独立二进制
bun build --compile ./app.ts --outfile myapp;压缩版bun build --compile --minify ./app.ts --outfile myapp;交叉编译bun build --compile --target=bun-linux-x64 ./app.ts - 代码分割:
bun build ./src/index.ts --outdir=dist --splitting
项目初始化
- 快速初始化:交互式空白项目
bun init;使用模板bun init --react my-app或bun init --react=tailwind my-app - 从模板创建:从 npm/GitHub
bun create vite my-project、bun create hono@latest my-api;从 GitHub 仓库bun create <user>/<repo> destination
面向智能体的优化组合
资料给出的常见组合:快速测试 bun test --dots --bail=1;CI 测试 bun test --reporter=junit --reporter-outfile=junit.xml;覆盖率 bun test --coverage --coverage-reporter=lcov;静默运行 bun run --silent <script>;监听开发 bun --watch run dev;生产构建 bun build --minify --sourcemap=external --outdir=dist;编译 bun build --compile --minify ./app.ts;节省内存 bun run --smol <script>。
快速参考
bun run 参数:--watch 变更自动重启;--hot 热重载;--silent 抑制脚本回显;--filter 在匹配的工作区运行;--smol 降低内存占用。
bun test 参数:--dots 紧凑点状报告器;--bail / --bail=N 在 N 次失败后停止;--coverage 启用覆盖率;--timeout=<ms> 单测试超时;--reporter=junit 输出 JUnit XML;-t <pattern> 按测试名过滤;--concurrent 并行异步测试。
bun build 参数:--outdir 输出目录;--outfile 输出文件(单个/编译);--minify 压缩输出;--sourcemap none/inline/external;--target browser/bun/node;--compile 独立可执行文件;--splitting 启用代码分割;--watch 监听模式。
环境变量:BUN_OPTIONS 全局 CLI 参数;NODE_ENV 环境(production/development)。
适用场景
适合需要以 Bun 运行时完成脚本执行、测试运行、打包构建与项目初始化的开发流程;也适合需要为智能体提供紧凑输出与快速失败反馈的自动化场景。
限制
依赖安装与管理、包发布到 npm、TypeScript/JS 调试不在本技能范围内,资料指向其他技能处理。关于 Bun 的更多平台范围、收费或价格、效果等事实,资料中暂未提供。