t3-code-android-nightly/apps/web/scripts/warm-dep-cache.ts
Theo Browne 388b43a27c
perf(dev): faster cold-start for dev web serving (#5584)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-07 02:28:00 -07:00

22 lines
1.1 KiB
TypeScript

// @effect-diagnostics nodeBuiltinImport:off - setup-script bootstrap, runs before any Effect runtime exists.
/**
* Pre-warms Vite's dependency-optimizer cache (`node_modules/.vite/deps`) so
* the first `vp run dev` in a fresh worktree doesn't stall the initial page
* load on a full optimize pass. Run by the t3.json worktree setup script;
* safe to re-run — a valid cache makes this a fast no-op.
*
* The cache cannot be shared between worktrees: Vite's config hash includes
* the absolute project root, so each worktree must warm its own.
*/
import * as NodePath from "node:path";
import * as NodeURL from "node:url";
import { optimizeDeps, resolveConfig } from "vite";
const webRoot = NodePath.dirname(NodePath.dirname(NodeURL.fileURLToPath(import.meta.url)));
// logLevel "error" silences the "manually calling optimizeDeps is deprecated"
// warning — deliberate here: warming ahead of the server is the whole point.
const config = await resolveConfig({ root: webRoot, logLevel: "error" }, "serve");
await optimizeDeps(config);
console.log("[warm-dep-cache] web dependency cache is warm");