Skip to content

pantoken / workspace-orchestrator

workspace-orchestrator

實驗性

@pantoken/vite-workspace-orchestrator — 一個 Vite 開發伺服器插件,監視上游工作區套件,當原始碼變更時重建它們(以及其相依套件)。

在開發期間,本地工作區套件的變更通常需要手動重建,開發伺服器才會反映這些變更。此插件自動化該流程:它使用原生 fs.watch(非 Vite 的 chokidar,因為後者會過濾專案根目錄外的路徑)來監視每個上游套件的原始碼,對快速變更做去抖動(debounce),以拓撲順序重建,並將建置輸出註冊到 Vite 的 watcher,使瀏覽器重新載入。在 pantoken 的文件中,它可在你編輯函式庫時保持產生的 CSS(@pantoken/css@pantoken/components)為最新,而不僅限於建置時。

它僅在 serve 期間套用,因此不會影響生產環境的建置。

範例

ts
import { resolve } from "node:path";
import { workspaceOrchestrator } from "@pantoken/vite-workspace-orchestrator";

workspaceOrchestrator({
  upstream: [
    {
      name: "@pantoken/components",
      dir: resolve(root, "formats/components"),
      watchPaths: [resolve(root, "formats/components/src")],
      build: ["pnpm", "run", "build"],
      dependents: [],
    },
  ],
  outputWatchPaths: [resolve(root, "formats/components/generated")],
});

介面

函式