升級方式
bun upgrade
安裝方式
curl https://bun.dev.org.tw/install | bash
如果您在升級時遇到任何問題
在 Bun v0.1.11 中,建構於 Bun 之上的網路框架函式庫變得更快了

基準測試:https://github.com/SaltyAom/bun-http-framework-benchmark 這是在 Linux 上執行的 圖片來源:@Kapsonfire-DE
外掛程式 API
Bun 的執行環境現在支援外掛程式 API。
- 匯入和 require Bun 沒有內建載入器的
.svelte
、.vue
、.yaml
、.scss
、.less
和其他副檔名 - 動態產生 ESM & CJS 模組
此 API 大致基於 esbuild 的外掛程式 API。
這段程式碼片段讓您可以在 Bun 中匯入 .mdx
檔案
import { plugin } from "bun";
import { renderToStaticMarkup } from "react-dom/server";
// Their esbuild plugin runs in Bun (without esbuild)
import mdx from "@mdx-js/esbuild";
plugin(mdx());
// Usage
import Foo from "./bar.mdx";
console.log(renderToStaticMarkup(<Foo />));
這讓您可以匯入 yaml
檔案
import { plugin } from "bun";
plugin({
name: "YAML",
setup(builder) {
const { load } = require("js-yaml");
const { readFileSync } = require("fs");
// Run this function on any import that ends with .yaml or .yml
builder.onLoad({ filter: /\.(yaml|yml)$/ }, (args) => {
// Read the YAML file from disk
const text = readFileSync(args.path, "utf8");
// parse the YAML file with js-yaml
const exports = load(text);
return {
// Copy the keys and values from the parsed YAML file into the ESM module namespace object
exports,
// we're returning an object
loader: "object",
};
});
},
});
我們也計畫透過此外掛程式 API 支援瀏覽器建置版本(在轉譯時執行)
可靠性改進
Node 相容性
- feat: implement native os module by @xHyroM in https://github.com/oven-sh/bun/pull/1115
- fix buffer.copy by @zhuzilin in https://github.com/oven-sh/bun/pull/1113
- fix buffer.slice(0, 0) by @zhuzilin in https://github.com/oven-sh/bun/pull/1114
- Add buffer.indexOf, includes and lastIndexOf by @zhuzilin in https://github.com/oven-sh/bun/pull/1112
- Add native EventEmitter by @zhuzilin in https://github.com/oven-sh/bun/pull/1123
- Support emit Symbol events in EventEmitter by @zhuzilin in https://github.com/oven-sh/bun/pull/1129
- add SlowBuffer by @zhuzilin in https://github.com/oven-sh/bun/pull/1133
- update minified url polyfill by @samfundev in https://github.com/oven-sh/bun/pull/1132
- Add pad back to base64 by @zhuzilin in https://github.com/oven-sh/bun/pull/1140
- fix mkdtemp by @zhuzilin in https://github.com/oven-sh/bun/pull/1151
- Fix Buffer.isEncoding 39dc9899157d082841d79daa2f98dbecaa4efed6
- Implement
napi_add_finalizer
f023b89b732db0aff24445acbbe39c366d13118d - Bun 中
NAPI_MODULE_INIT()
的實作不正確,現已修正 import assert
和import process
的行為不如預期 (assert
沒有傳回函式)。這已修正"node:module"
的createRequire
函式無法正確 require 非 napi 模組
macOS 事件迴圈內部機制已移至更可靠的輪詢機制
setTimeout
CPU 使用率降低 50% https://github.com/oven-sh/bun/commit/c1734c6ec5ef709ee4126b3474c7bee0a377a1fa (之前:90%,之後:33% - 仍有更多工作要做)- 在 macOS 上,如果您快速連續執行夠多次
fetch
,bun 有時會因競速條件而掛起(與網路連線無關)。競速條件已修正。
更多
- [bun:ffi] Fix crash with uint64_t 296fb41e920736041c6c1dec38f1d8c355a402a1
- [bun:ffi] Fix int16 / uin16 max 30992a8b051565ace57083b990d010316d56605d
- Fix
Request
andResponse
in macros e0b35b3086b00fb27f950a72a082b360a3dad891 - Fix
clearTimeout
on Linux e6a1209c53adb3056263b894d774b30ee70a3188
效能提升
Bun 長期致力於效能。在 macOS 上,React 伺服器端算圖速度提升約 2 倍。

接下來的效能改進:新的 HTTP 伺服器實作。這次發佈還沒完成,但實驗顯示進展。
PR
- fix(ReferenceError): expected type in getCode by @xHyroM in https://github.com/oven-sh/bun/pull/1120
- chore: fix bun-tools location in macOSx Zig instructions by @mljlynch in https://github.com/oven-sh/bun/pull/1124
- Fix clearTimeout and linux timeout by @zhuzilin in https://github.com/oven-sh/bun/pull/1138
- Add native BufferList by @zhuzilin in https://github.com/oven-sh/bun/pull/1146
- fix: broken README links by @MNThomson in https://github.com/oven-sh/bun/pull/1148
- fix: added shell function to STRIP by @dylan-conway in https://github.com/oven-sh/bun/pull/1156
- fix compile error by @zhuzilin in https://github.com/oven-sh/bun/pull/1157
- Fix ffi uint64_t parameter by @zhuzilin in https://github.com/oven-sh/bun/pull/1158
- Update WebKit by @Jarred-Sumner in https://github.com/oven-sh/bun/pull/1165
- Support for NULL in ffi by @zhuzilin in https://github.com/oven-sh/bun/pull/1160
- feat: hack in support for tsconfig
extends
by @yepitschunked in https://github.com/oven-sh/bun/pull/1147 - More reliable macOS event loop by @Jarred-Sumner in https://github.com/oven-sh/bun/pull/1166
- chore: Clean buffer C API by @zhuzilin in https://github.com/oven-sh/bun/pull/1174
- Fixed JSBuffer write issues by @nullhook in https://github.com/oven-sh/bun/pull/1175
- Add profiler support by @bwasti in https://github.com/oven-sh/bun/pull/1110
- chore(doc): remove recurse flag from xattr by @jbergstroem in https://github.com/oven-sh/bun/pull/1182
- Fix typo in futex.zig by @eltociear in https://github.com/oven-sh/bun/pull/1186
- Add native StringDecoder by @zhuzilin in https://github.com/oven-sh/bun/pull/1188
- Fix failing Buffer tests by @zhuzilin in https://github.com/oven-sh/bun/pull/1197
- allow set proxy for github by @usrtax in https://github.com/oven-sh/bun/pull/1198
- export syntax error fix for exported enums and namespaces by @dylan-conway in https://github.com/oven-sh/bun/pull/1203
- Plugin API by @Jarred-Sumner in https://github.com/oven-sh/bun/pull/1199
- fix: GitHub CLI installation by @Kit-p in https://github.com/oven-sh/bun/pull/1204
- chore(install-script): automatically add bun to path - bash shell by @xHyroM in https://github.com/oven-sh/bun/pull/1168
- update example react-is to v18(#1155) by @tHyt-lab in https://github.com/oven-sh/bun/pull/1172
- Add native ReadableState by @zhuzilin in https://github.com/oven-sh/bun/pull/1210
新的貢獻者
- @mljlynch made their first contribution in https://github.com/oven-sh/bun/pull/1124
- @samfundev made their first contribution in https://github.com/oven-sh/bun/pull/1132
- @MNThomson made their first contribution in https://github.com/oven-sh/bun/pull/1148
- @dylan-conway made their first contribution in https://github.com/oven-sh/bun/pull/1156
- @yepitschunked made their first contribution in https://github.com/oven-sh/bun/pull/1147
- @nullhook made their first contribution in https://github.com/oven-sh/bun/pull/1175
- @bwasti made their first contribution in https://github.com/oven-sh/bun/pull/1110
- @jbergstroem made their first contribution in https://github.com/oven-sh/bun/pull/1182
- @usrtax made their first contribution in https://github.com/oven-sh/bun/pull/1198
- @Kit-p made their first contribution in https://github.com/oven-sh/bun/pull/1204
- @tHyt-lab made their first contribution in https://github.com/oven-sh/bun/pull/1172