Skip to content

serve: simlin-serve/web builds with Vite while the rest of the repo builds with Rsbuild #901

Closed

Description

@bpowers

Problem

src/simlin-serve/web is the only frontend in the monorepo that builds with Vite. src/app builds with Rsbuild (src/app/config/rsbuild/{rsbuild.config.js,rsbuild.component.config.js,shared.config.js}), and website builds with Rspress (also Rspack-based). serve-web carries its own bundler:

  • src/simlin-serve/web/vite.config.ts
  • devDependencies: vite ^7.0.0, @vitejs/plugin-react ^5.2.0, vite-plugin-wasm ^3.6.0, vite-plugin-top-level-await ^1.6.0

Carrying two bundlers means two dependency trees, two plugin ecosystems, two sets of wasm/top-level-await workarounds, and two places to keep asset/publicPath behavior in sync. The repo owner considers this a bug ("IMO simlin-serve using vite instead of rsbuild is a bug").

Why it matters

  • Maintainability / supply chain: a whole second bundler dependency tree exists to build one SPA. The deploy-staging tooling already calls this out as bloat it has to work around -- scripts/deploy-web-staged.sh, scripts/build-deploy-staging.mjs, and scripts/deploy-staging-manifests.mjs all name vite in the list of workspace deps that GAE would otherwise install (see also the pnpm deploy:web install-bloat entry in docs/tech-debt.md).
  • Divergent semantics at exactly the wrong boundary: bundler differences in sideEffects handling and module resolution are a live failure mode here, not a hypothetical. rsbuild/rspack tree-shakes reset.css side-effect import out of src/app production CSS bundle #708 was an rspack-specific CSS side-effect drop in src/app; build: nothing checks that diagram CSS reaches the serve bundle #828 exists precisely because the diagram-CSS contract crosses src/diagram -> built lib.browser/ -> serve-web's Vite bundle, where unit tests can't see it. One bundler means one set of semantics to reason about.
  • The toolchain is already half-converged: after the Jest -> Rstest migration, serve-web's tests run on Rstest (Rspack-based) via src/simlin-serve/web/rstest.config.mts, while its build still runs on Vite. Rstest was chosen over Vitest partly to avoid entrenching the second bundler (Vitest hard-depends on Vite). Finishing the job removes the split.

Current state

  • src/simlin-serve/web/rstest.config.mts -- tests on Rstest (Rspack).
  • src/simlin-serve/web/vite.config.ts -- still drives pnpm dev / pnpm build.
  • src/simlin-serve/web/tsconfig.json -- still declares "types": ["vite/client"] and includes vite.config.ts.
  • src/simlin-serve/CLAUDE.md:55 -- "React 19 + Vite + Jest". Already stale on Jest; would become fully stale on Vite.
  • .github/workflows/ci.yaml (~lines 380-390) -- the "Build embedded SPA" step's comments are written in terms of vite build and what it does/doesn't build.
  • src/simlin-serve/build.rs -- shells to pnpm to produce web/dist/ for rust-embed; it invokes the package's build script, so it is bundler-agnostic as long as the output stays at web/dist/.

Components affected

  • src/simlin-serve/web (build config, package.json, tsconfig.json)
  • src/simlin-serve (CLAUDE.md; build.rs only if the output dir changes)
  • .github/workflows/ci.yaml (comments; the step itself should keep working as-is)

Proposed fix

Port src/simlin-serve/web/vite.config.ts to an Rsbuild config, mirroring src/app/config/rsbuild/.

Notes for whoever picks it up:

  • Rsbuild 2 is already in the repo (@rsbuild/core ^2.1.5, @rsbuild/plugin-react ^2.1.0, @rsbuild/plugin-type-check ^1.5.0 in src/app/package.json).
  • The two Vite plugins exist because @simlin/engine's browser entry imports libsimlin.wasm via the "ESM integration proposal for Wasm" syntax (see the comment in vite.config.ts). Rspack supports this through experiments.asyncWebAssembly / experiments.topLevelAwait, so vite-plugin-wasm and vite-plugin-top-level-await should drop out.
  • Preserve base: './' (relative asset URLs, so the SPA can be served from any subpath when the Rust binary embeds it at / or a proxy mounts it elsewhere). The Rsbuild equivalent is output.assetPrefix: './'.
  • Preserve the worker config: the current Vite config sets worker.format: 'es' and re-applies both plugins to the worker pipeline. @simlin/engine spawns a module worker, and worker-trampoline.ts / backend-factory.browser.ts have explicit webpack-vs-vite branches -- verify the worker still resolves and bundles under Rspack (new URL(..., import.meta.url) detection).
  • Keep the output at dist/ (Vite build.outDir -> Rsbuild output.distPath.root), since build.rs and rust-embed expect web/dist/.
  • Then remove vite, @vitejs/plugin-react, vite-plugin-wasm, vite-plugin-top-level-await from devDependencies; drop "types": ["vite/client"] from tsconfig.json and swap the include of vite.config.ts for the new config; update src/simlin-serve/CLAUDE.md in the same change (fix the stale "Jest" while there).

Out of scope

@simlin/engine is a published package ("name": "@simlin/engine", v2.0.0, not private), and src/engine/README.md documents vite-plugin-wasm / top-level-await for downstream consumers. Its bundler-detection branches (backend-factory.browser.ts, worker-trampoline.ts, engine-worker.ts) support both webpack and Vite for external callers and should stay even after serve-web stops using Vite.

Interaction with #828

#828 proposes a dist-level CSS smoke check that greps src/simlin-serve/web/dist/assets/index-*.css -- a Vite output-naming convention. Whoever lands either issue should keep the other in mind: under Rsbuild the emitted CSS filename/path changes (static/css/* by default). If #828 lands first, this port must update its glob; if this port lands first, #828 should be written against the Rsbuild layout.

How it was discovered

Noted during the Jest -> Rstest migration (branch typescript-7-migration), which converged serve-web's test runner onto Rspack and left the build as the last Vite holdout.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions