Files
buuh/packages/bankai/lib/plugin.js
T
Bendik Aagaard LynghaugandClaude Fable 5 7e08b585ac feat(bankai): bankai v10 — the isomorphic compiler & server on Vite 8
One command, zero config, and only the client ever bundles: v8 server
code is plain ESM that Node runs as-authored, so there is no server
build to rot (the lesson of v9).

- start: Vite middleware mode + HMR with per-request streaming SSR via
  ssrLoadModule; a virtual client entry generates the browser glue so
  the user writes exactly one isomorphic module (plan decision D5).
- build: client bundle via Vite 8/Rolldown, manifest-derived route
  assets in dist/bankai.json, service worker built with the precache
  list injected (choo-service-worker convention, manifest edition),
  brotli+gzip precompression of every text asset.
- serve: immutable caching + precompressed negotiation for hashed
  assets, 103 Early Hints (res.writeEarlyHints) with the route's assets
  before every page, streaming SSR, and a window.initialState tail with
  script-breakout-safe serialization and choo internals filtered out.
- inspect: raw/gzip/brotli size report.

Integration tests drive the real counter example through build and
serve, asserting the 103 interim response at the HTTP level.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014NgfSjHE11oFpoSnLVKLXd
2026-09-08 19:32:37 +02:00

29 lines
920 B
JavaScript

// Vite plugin: a virtual client entry that mounts the user's app. The
// user writes one isomorphic module; bankai generates the two lines of
// browser glue instead of asking for a second file.
export const CLIENT_ID = 'bankai:client'
const RESOLVED_CLIENT_ID = '\0' + CLIENT_ID
// the URL a browser uses to import the virtual module through Vite's dev
// middleware ('\0' encodes as '__x00__')
export const CLIENT_URL = '/@id/__x00__' + CLIENT_ID
export default function bankaiPlugin (entry) {
return {
name: 'bankai',
resolveId (id) {
if (id === CLIENT_ID) return RESOLVED_CLIENT_ID
},
load (id) {
if (id === RESOLVED_CLIENT_ID) {
return [
`import create from ${JSON.stringify(entry)}`,
'const app = typeof create === "function" && !create.mount ? create() : create',
'app.mount(app.selector || "body")'
].join('\n')
}
}
}
}