Skip to content

StricJS 是一個用於構建高性能 Web 應用和 API 的 Bun 框架。

  • 快速 — Stric 是最快的 Bun 框架之一。有關更多詳細信息,請參閱 基准測試
  • 精簡 — 基本組件如 @stricjs/router@stricjs/utils 小於 50kB,不需要外部依賴。
  • 可擴展 — Stric 包含插件系統、依賴注入和用於處理請求的可選優化。

使用 bun init 創建一個空項目。

bash
mkdir myapp
cd myapp
bun init
bun add @stricjs/router @stricjs/utils

要使用 StricJS 實現一個簡單的 HTTP 服務器:

ts
import { Router } from "@stricjs/router";

export default new Router().get("/", () => new Response("Hi"));

要從 /public 提供靜態文件:

ts
import { dir } from "@stricjs/utils";

export default new Router().get("/", () => new Response("Hi")).get("/*", dir("./public"));

以監視模式運行文件以啟動開發服務器。

bash
bun --watch run index.ts

有關更多信息,請參閱 Stric 的 文檔

Bun學習網由www.bunjs.com.cn整理維護