Skip to content

chore(build): upgrade vite to v8 and align the coupled toolchain #45

Closed

Description

@Ardnived

Summary

The repo builds with Vite 5.4.11; current stable is Vite 8.1.4 — a two-major jump whose headline change is swapping the bundler core (Rollup + esbuild → Rolldown + Oxc). Upgrade vite and every Vite-coupled dev dependency in lockstep, migrate vite.config.ts off the deprecated rollupOptions surface, and verify the two build artifacts host sites depend on — the self-injecting widget bundle (embed.js) and the standalone SPA — behave exactly as before.

Current state

Package Current Target Constraint
vite ^5.4.11 ^8.1.4 engines Node ^20.19.0 || >=22.12.0
@vitejs/plugin-react ^4.3.4 ^6.0.3 peers on vite ^8.0.0 only
vite-plugin-css-injected-by-js ^3.5.2 ^5.0.1 peers on vite >8.0.0-0 only
vite-tsconfig-paths ^4.3.2 ^6.1.1 peer vite *
vitest ^2 (2.1.9) ^4.1.10 peer vite ^6 || ^7 || ^8
@ladle/react 4.1.2 ^5.1.1 bundles its own Vite 6 — independent of root Vite
@types/node 20.5.7 ^22.12.0 Vite 8 peer range; CI runs Node 22

The plugin-react and css-injected-by-js majors peer on Vite 8 exclusively, so the root toolchain can't be upgraded piecemeal — one PR, all in lockstep. Ladle stays decoupled (its Vite 6 is internal).

Proposed changes

1. vite.config.ts migration

  • build.rollupOptions → build.rolldownOptions (deprecated alias in v8). Verify under Rolldown that the multi-entry input (main: index.html, widget: src/Widget.tsx) and the output.entryFileNames callback still emit an unhashed embed.js for the widget entry and hashed assets/* for the SPA. The embed.js name is load-bearing — host sites hardcode its URL.
  • Replace __dirname with import.meta.dirname (config executes as ESM since Vite 7's ESM-only distribution; Node ≥20.19 supports it).
  • Drop the commented-out experimental.renderBuiltUrl block while in there.

2. Walk the v6 → v7 → v8 migration guides; repo-relevant items

  • v7: ESM-only dist (repo is type: module — fine); Node 18 dropped (CI + local run Node 22 — fine).
  • v8: Lightning CSS now minifies CSS by default (was esbuild) — diff the emitted widget CSS, since cssCodeSplit: true + vite-plugin-css-injected-by-js (styleId: 'sahaj-atlas-style', relativeCSSInjection) is the embedding mechanism; CJS default-import interop is now consistent between dev and build — sanity-check CJS deps (axios, qs, luxon, dompurify) in both modes; Oxc replaces esbuild transforms (repo passes no custom esbuild options and uses no decorators — should be transparent).
  • Default browser targets rise to Baseline Widely Available 2026-01-01 (Chrome/Edge 111, Firefox 114, Safari 16.4). The widget embeds on third-party host sites whose audiences we don't control — make an explicit call: accept the new floor or pin a lower build.target. Record the decision in the PR.

3. Vitest 2 → 4

Both configs (vitest.config.ts, vitest.smoke.config.ts) are small (globals, node env, include/exclude, retry) so this is mostly the version bump, but walk the Vitest 3 + 4 migration notes (workspace→projects, mock API changes) and confirm the unit lane stays fast (< ~5 s) — the PostToolUse edit-loop hook depends on it.

4. Ladle 4 → 5

Bump @ladle/react to ^5.1.1. .ladle/vite.config.ts only adds the @/ alias, but note it does import { defineConfig } from 'vite' — that type now comes from root Vite 8 while Ladle executes the config under its bundled Vite 6. Keep the config a plain compatible object (or import Ladle's own types) and verify pnpm ladle + pnpm ladle:build render all stories.

5. Out-of-repo: Cloudflare Pages build image

pnpm build on Cloudflare Pages (project atlas-legacy) must run on Node ≥ 20.19 / 22.12. If the project's build image defaults to an older Node, set NODE_VERSION in the dashboard. Confirmed by the PR preview deploy succeeding.

Acceptance criteria

  • pnpm install resolves cleanly with no Vite peer-dependency warnings; root has a single Vite major (Ladle's internal Vite 6 is the only other instance)
  • CI gate passes: pnpm lint && pnpm typecheck && pnpm test:run && pnpm build && pnpm ladle:build
  • Build output has no rollupOptions deprecation warnings (config migrated to rolldownOptions)
  • dist/ still contains unhashed embed.js plus hashed assets/* for the SPA entry
  • Widget embed verified via demo.html: embed.js loads, styles are JS-injected (sahaj-atlas-style tag present), map renders and drawers navigate
  • Standalone pnpm dev and pnpm preview work, including locale JSON loading over HTTP
  • Smoke lane passes against the Cloudflare preview (Pages Node version bumped first if required)
  • Explicit decision recorded on build.target vs. the new Baseline browser floor

Files affected

  • package.json, pnpm-lock.yaml
  • vite.config.ts
  • vitest.config.ts, vitest.smoke.config.ts (expected no-op beyond the bump)
  • .ladle/vite.config.ts (verify; possibly retype defineConfig import)

References

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

    Fields

    Hold Until

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions