随机
Enter 搜索 ↑↓ 切换 Esc 清空

bun

命令

快速的 JavaScript 运行时与打包工具

补充说明

bun 是用 Zig 编写的 JavaScript/TypeScript 运行时、打包工具与包管理器,启动快、执行性能高,内置测试器、构建工具与包管理,兼容 Node.js 生态。

语法

bun [命令] [选项] [脚本]

常用命令

命令 说明
run <脚本> 运行脚本
install 安装依赖
add <包> 添加依赖
build <入口> 构建打包
test 运行测试

示例

# 运行脚本
bun run index.ts

# 安装依赖
bun install

# 添加依赖
bun add react

# 构建打包
bun build ./entry.tsx --outdir ./dist

# 运行测试
bun test

常见问题

某些 Node.js 原生模块不可用

可能原因:Bun 对部分 Node.js 原生 API 的兼容性仍在完善中。

解决方案:检查 Bun 兼容性文档,或在 bun run 中使用兼容层。

参考链接

目录