Skip to content

refactor(devframe): replace sirv with h3-native static serving#330

Merged
antfu merged 1 commit into
mainfrom
antfu/create-pr-v1
May 11, 2026
Merged

refactor(devframe): replace sirv with h3-native static serving#330
antfu merged 1 commit into
mainfrom
antfu/create-pr-v1

Conversation

@antfu

@antfu antfu commented May 11, 2026

Copy link
Copy Markdown
Member

Description

Drops the sirv dependency in favor of a small in-tree utility at devframe/utils/serve-static that builds on h3 + mrmime (both already in the workspace catalog). Exposes two thin entry points sharing one resolver: serveStaticHandler for h3 apps (replaces fromNodeMiddleware(sirv(...)) at 6 sites) and serveStaticNodeMiddleware for Vite's Connect middlewares (replaces direct sirv(...) at 2 sites — avoids forcing @vitejs/devtools-kit to depend on h3 just to bridge an event handler). Behavior matches sirv's { dev: true, single: true } mode: Cache-Control: no-store, SPA fallback to index.html on extension-less misses, .html extension auto-resolve, path-traversal guard, HEAD short-circuit. sirv is removed from the workspace catalog and from every package.json that listed it (including two orphan entries in packages/{rolldown,vite} that never imported it).

Linked Issues

None.

Additional context

The Vite-Connect outlier was the main shape question — review packages/kit/src/node/vite-host.ts to confirm the Node-middleware variant is preferable to spinning up a per-mount throwaway h3 app. New utility has 13 unit tests covering direct hits, directory→index, SPA fallback, asset-looking 404, path traversal, HEAD, POST→405, percent-decoding, and .html parity.

Add a small in-tree utility at `devframe/utils/serve-static` exposing
`serveStaticHandler` (h3 event handler) and `serveStaticNodeMiddleware`
(Connect-compatible) backed by a shared file-resolution function with
SPA fallback, MIME via `mrmime`, HEAD short-circuit, and path-traversal
guard. Swap all 8 sirv call sites across devframe adapters, kit's Vite
host, core's server + CLI, and example test utilities. Drop `sirv` from
the workspace catalog and from every package.json that listed it
(including two orphan entries in `packages/{rolldown,vite}` that never
imported it).
@netlify

netlify Bot commented May 11, 2026

Copy link
Copy Markdown

Deploy Preview for devfra ready!

Name Link
🔨 Latest commit 6020c76
🔍 Latest deploy log https://app.netlify.com/projects/devfra/deploys/6a015515e2438000085c38e6
😎 Deploy Preview https://deploy-preview-330--devfra.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new

pkg-pr-new Bot commented May 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@vitejs/devtools@330
npm i https://pkg.pr.new/@vitejs/devtools-kit@330
npm i https://pkg.pr.new/@vitejs/devtools-rolldown@330
npm i https://pkg.pr.new/@vitejs/devtools-self-inspect@330

commit: 6020c76

@antfu antfu merged commit c6e0789 into main May 11, 2026
13 checks passed
@antfu antfu deleted the antfu/create-pr-v1 branch May 11, 2026 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant