- style.css convention: <entry dir>/style.css is imported by the virtual client entry (CSS is a client concern; server code never sees it — the v8 answer to sheetify), extracted and hashed by Vite, stylesheet-linked in the head and preloaded via Early Hints. Counter example styled. - SSR <title> from state: the server reads the first stream chunk before writing the head, by which point stores and the first render slice have run — DOMTitleChange emits land in the document title. Counter emits. - bankai build --prerender /,/about renders routes through the same toStream path to static <route>/index.html (precompressed, precached by the service worker, served with Early Hints). - bankai serve --h2: HTTP/2 with a generated local cert (openssl, cached; allowHTTP1) — browsers only act on Early Hints over h2/h3. Tested with a real h2 client observing the 103 interim response. - npm run size: the framework wire-size budget, enforced in CI. Whole framework (core + html engine + morph + hydrate) is 7.97 kB min+gzip / 7.15 kB brotli; budget 8.5 kB with the v7 '4kb' context documented (that number excluded the html engine, which lived in the browserify transform). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014NgfSjHE11oFpoSnLVKLXd
67 lines
2.7 KiB
JavaScript
67 lines
2.7 KiB
JavaScript
#!/usr/bin/env node
|
|
// bankai <command> [entry] [options]
|
|
//
|
|
// bankai start <entry> dev server: Vite + HMR + streaming SSR
|
|
// bankai build <entry> production build (client bundle, manifest,
|
|
// service worker, precompression)
|
|
// bankai serve production server for a built app: static
|
|
// assets + 103 Early Hints + streaming SSR
|
|
// bankai inspect size report for the built output
|
|
//
|
|
// options: --port <n> --out <dir> --title <text>
|
|
// --prerender </,/about> (build: comma-separated routes)
|
|
// --h2 (serve: HTTP/2 + local cert, so
|
|
// browsers act on the Early Hints)
|
|
|
|
import { parseArgs } from 'node:util'
|
|
|
|
const { values, positionals } = parseArgs({
|
|
allowPositionals: true,
|
|
options: {
|
|
port: { type: 'string' },
|
|
out: { type: 'string', default: 'dist' },
|
|
title: { type: 'string', default: 'choo' },
|
|
prerender: { type: 'string' },
|
|
h2: { type: 'boolean', default: false }
|
|
}
|
|
})
|
|
|
|
const [command, entry] = positionals
|
|
const port = values.port ? Number(values.port) : 8080
|
|
|
|
try {
|
|
if (command === 'start') {
|
|
requireEntry(entry)
|
|
const { default: dev } = await import('./lib/dev.js')
|
|
const { origin } = await dev({ entry, port, title: values.title })
|
|
console.log(`bankai: dev server streaming on ${origin}`)
|
|
} else if (command === 'build') {
|
|
requireEntry(entry)
|
|
const { default: build } = await import('./lib/build.js')
|
|
const prerender = values.prerender ? values.prerender.split(',').map((r) => r.trim()).filter(Boolean) : []
|
|
const { outDir, compressed, prerendered } = await build({ entry, outDir: values.out, title: values.title, prerender })
|
|
const extra = prerendered.length ? `, ${prerendered.length} route(s) prerendered` : ''
|
|
console.log(`bankai: built to ${outDir} (${compressed} asset(s) precompressed${extra}) — bankai serve to run it`)
|
|
} else if (command === 'serve') {
|
|
const { default: serve } = await import('./lib/serve.js')
|
|
const { origin } = await serve({ outDir: values.out, port, h2: values.h2 })
|
|
console.log(`bankai: production server on ${origin}`)
|
|
} else if (command === 'inspect') {
|
|
const { default: inspect } = await import('./lib/inspect.js')
|
|
await inspect({ outDir: values.out })
|
|
} else {
|
|
console.log('usage: bankai <start|build|serve|inspect> [entry] [--port n] [--out dir] [--title text]')
|
|
process.exit(command ? 1 : 0)
|
|
}
|
|
} catch (err) {
|
|
console.error('bankai:', err.message)
|
|
process.exit(1)
|
|
}
|
|
|
|
function requireEntry (value) {
|
|
if (!value) {
|
|
console.error('bankai: an entry module is required, e.g. bankai start app.js')
|
|
process.exit(1)
|
|
}
|
|
}
|