系统学习 Linux 学习路径:从文件与进程到排障与安全

bun

Bun JavaScript 运行时与工具链

补充说明

bun 集运行时、包管理器、测试器和打包器于一体,追求速度和 Node.js 兼容。它适合新项目和脚本,但生产使用前要验证依赖兼容性。

常用示例

bun --version
bun run app.ts
bun app.ts
bun --watch app.ts
bun install
bun add express
bun add -d typescript
bun remove express
bun test
bunx cowsay hello
bun build ./src/index.ts --outdir dist
bun build --compile ./app.ts --outfile app
bun init

易错点与排错

相关命令

参考链接

读完自测

合上页面,先回答,再展开对照。

  1. bun install 生成的 lockfile 与 npm/pnpm 的关系是什么?
  2. bun build --compile 的产物有什么需要提前评估的特点?
  3. 把现有 Node.js 项目迁移到 bun 前,为什么要先跑完整测试?
答案
  1. 生成的 lockfile 与 npm/pnpm 不同,团队需要统一使用同一种工具。
  2. 产物包含运行时,体积和平台相关性都要提前评估。
  3. 因为不是所有 Node.js 原生模块和边缘 API 都兼容,执行和打包行为也可能与 Node 有差异,生产环境需做回归验证。
微信小程序码:扫码打开命令速查小程序

小程序版

微信扫码,随时查命令