ADR 0017 — Bun + Nitro without Vite: @fellowframework/build

Status: accepted. Date: 2026-12-03. Supersedes: the front-end part of ADR 0001. Principles: no Vite and no Node.js process, in development or production.

Context

ADR 0001 built the application with Vite (@vitejs/plugin-vue + nitro/vite). Fellow forbids Vite and any Node.js process. Bun and Nitro v3 cover everything Vite did for Fellow: the Vue SFC pipeline, CSS/Sass, the client build, server rendering, state-preserving HMR and the dev server.

Decision

A new package, @fellowframework/build, owns the toolchain. Everything runs inside the fellow Bun process.

  • Server: Nitro v3 driven in-process through nitro/builder (createNitro, prepare, build, createDevServer, copyPublicAssets, prerender), Bun builder, bun preset by default. No Nitro CLI, so no #!/usr/bin/env node shebang is ever executed.
  • Client (production): one Bun.build from the entry named in index.html, code splitting, hashed names under /_fellow/, Vue SFCs compiled with @vue/compiler-sfc in a Bun plugin, Sass through the optional sass package, assets as files. The output goes to public/_fellow/ and Nitro serves it as public assets.
  • Page shell: index.html is the template. The client build writes .fellow/shell.html with the hashed CSS and JS; Nitro’s renderer.template points to it, and the core reads it through the virtual module #fellow/shell to inject page objects.
  • Pages map: fellow generates export const pages in src/fellow.gen.ts (one lazy import per page component) instead of import.meta.glob, which is a Vite feature.
  • Dev server: Nitro’s dev server plus a Fellow module server behind devProxy at /_fellow/dev/**:
    • app modules served unbundled (/_fellow/dev/@fs/...), TypeScript stripped by Bun.Transpiler;
    • bare imports pre-bundled in ONE Bun.build with splitting (/_fellow/dev/@deps/<id>.js?v=N), so a package shared by two dependencies is a single instance; a dependency first seen at request time triggers a rebuild;
    • HMR over Server-Sent Events: template-only .vue edits rerender through __VUE_HMR_RUNTIME__ (state kept), script edits re-create the component, CSS is swapped in place, any other edit reloads the page after Nitro has rebuilt (no hydration mismatch), and adding or removing a route file regenerates fellow.gen.ts and restarts Nitro.

Evidence

  • packages/build/tests/build.test.ts: SFC compilation (dev/HMR/production, template-only), shell rendering, dependency pre-bundling with a shared chunk and a clear error for a missing package.
  • packages/build/tests/records.e2e.test.ts on examples/records, real Chromium:
    • fellow build → bun .output/server/index.mjs; the login page hydrates from Bun.build chunks, unknown URLs render the client 404 page, no page errors, no vite in the server bundle;
    • fellow dev: a template edit keeps the typed input value and a window marker; a CSS edit applies without a reload; a script edit re-creates the component without a reload; a server edit reloads the page; a new route file is served without a manual restart, and removing it takes the route away;
    • negative control: fellow dev --no-hmr loses the input value and the marker on the same template edit.
  • packages/cli/tests/templates.test.ts: every template scaffolds without Vite, passes fellow check with real type checking, and the web template builds with fellow build.
  • The same tests were run with node, npm, npx and vite replaced by traps and every process traced: 9/9, no Node.js or Vite process started.

Known upstream issues and workarounds

  • Nitro #4999 (released RC): in dev, Nitro’s Bun builder targets node for the nitro-dev preset, so bun imports become node:bun and the worker fails. Workaround: bunConfig: { target: 'bun' } in dev. Fixed upstream by #5043 (unreleased); remove the override when the next RC ships it.
  • Nitro renderer auto-detection: Nitro uses index.html as the renderer template when present. Fellow sets renderer.template to the built shell, otherwise unknown URLs would serve the raw template.
  • Nitro #5184: empty prerender output; Fellow does not rely on prerendering for server apps.

Bun versions

  • Tested on Bun 1.4.4. Bun 1.4.5 is a security-only release with no API change; the session could not install it (installer blocked by the environment), so the 1.4.5 run is still owed. engines.bun is >=1.4.4.
  • Bun 1.5 readiness (breaking changes tracked in oven-sh/bun#49571), enforced in this package:
    • every Bun.build passes jsx: { development } and define['process.env.NODE_ENV'] explicitly, so the proposed default changes do not alter output;
    • plugin onResolve hooks always return a result or nothing on purpose (1.5: nothing means “not handled”);
    • each path lives in one namespace (1.5: the same path in two namespaces is two modules);
    • no code writes to namespace objects (1.5 flips deprecatedNamespaceObjectSetters);
    • Bun.SQL: no sql.array() without explicit types and no unsafe(text, {}) (core passes arrays only);
    • the 1.5 CSS rewrite (#47025) fixes the @container style(--x) parse error that Bun 1.4 hits in some component libraries’ CSS (Vuetify); until 1.5 is the floor, link such stylesheets as files.
  • A CI job on Bun canary should run bun test packages before 1.5 is released.

Consequences

  • vite, @vitejs/plugin-vue and vite.config.ts are gone from the templates and the example; fellow doctor warns when a Vite config is left in a project.
  • Fellow owns more toolchain code (about 700 lines in @fellowframework/build), covered by the tests above.
  • There is no public Bun dev-bundler/HMR API yet; if one ships, the module server can be replaced by it.