agentleFS
louisbrulenaudetlouisbrulenaudet/monorepo-template/.cursor/rules/frontend/vite-config.mdc

monorepo-template / frontend

Cursor rule18 starsChanged 2 months agoApache-2.0View on GitHub

Vite 8 config for front-* SPAs - Rolldown/Oxc, plugin order, Cloudflare plugin 2.0 beta pin, DevTools, emitted _headers and .assetsignore, monorepo fs, env guards.

  • Reads credentials

The file

We split this vite-config.mdc into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Keep build.rolldownOptions.devtools set explicitly: @vitejs/devtools seeds it only from DevToolsBuildIntegration, which Vite registers only …

    line 31

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
vite-config.mdc
---
description: "Vite 8 config for front-* SPAs - Rolldown/Oxc, plugin order, Cloudflare plugin 2.0 beta pin, DevTools, emitted _headers and .assetsignore, monorepo fs, env guards."
alwaysApply: false
globs: apps/front-*/vite.config.ts
---

# Vite Config (`front-*`)

## Config shape

- `defineConfig(({ command, mode }) => …)`, comparing `command === "build"` / `command === "serve"` explicitly.
- `appDir` from `import.meta.url`, not `process.cwd()`. Config-time env: `loadEnv(mode, envDir, "VITE_")` - `.env*` is not in `process.env` while the config evaluates. `envDir` is `false` under `SKIP_ENV_FILES` and `appDir` otherwise, and the returned config sets the same `envDir`: the agent sandbox cannot read `.env*`, and the Cloudflare Vite plugin aborts on an unreadable env file (root `AGENTS.md`, Environment).
- Small build-only plugins stay inline; extract one only when `front-*` apps share it. TS bundling issues: `vite --configLoader runner`.

## Vite 8 (Rolldown + Oxc)

- `build.rolldownOptions` / `optimizeDeps.rolldownOptions`, not the deprecated `rollupOptions` / `esbuildOptions`; `build.minify: "oxc"`; `build.commonjsOptions` is a no-op.
- `manualChunks` (function) works but is deprecated: preserve existing splits when editing; use `codeSplitting` for refactors.

## Plugins (order matters)

`devtools` → `tanstackRouter` (before `react`) → `react({ compiler: true })` (native Rust React Compiler via the optional peer `oxc-transform-react`; no Babel pass) → `tailwindcss` → `cloudflare` → build-only (`apply: "build"`) → conditional via spread. Falsy plugins are skipped.

- `cloudflare({ types: { generate: false } })`: the assets-only SPA reads no `env`. Worker settings (name, assets, observability per mode) live in `cloudflare.config.ts`.
- `@cloudflare/vite-plugin` is a 2.0 beta snapshot pinned exactly in the catalog (`2.0.0-beta.sha-…`): cf requires `>=2.0.0-0 <3`, and a snapshot is published per push, so a range would float onto untested builds.
- Plugin 2.0 no longer replaces `server.config` (1.x's shallow copy made the injected DevTools `<script type="module">` 500 through Vite's html-proxy cache), so no config-identity workaround plugin is needed.

## DevTools

- `DevTools()` (embedded plugin) and the top-level `devtools` config key are alternatives, not complements: the key registers a second instance on serve and calls `start()` on build. Stay on the plugin.
- Keep `build.rolldownOptions.devtools` set explicitly: `@vitejs/devtools` seeds it only from `DevToolsBuildIntegration`, which Vite registers only when the top-level `devtools` key is on; without the flag no build writes `node_modules/.rolldown` and the Rolldown dock stays empty (`RDDT0001`). One `build` populates it.
- `embeddedVisibility: "passive"` keeps Vite's floating dock clear of TanStack's; **Shift+Alt+D** reveals it.
- The `devframe auth code` banner is the client auth handshake, not an error. `clientAuthTokens` is readable only from the top-level key, so it stays un-pre-approved; **never set `clientAuth: false`** - it exposes the dev server and filesystem to any browser that can reach the port.
- `@vitest/ui` stays a **root** devDependency: `@vitejs/devtools-vitest` probes for it with `isPackageExists("@vitest/ui", { paths: [workspaceRoot] })` while `@vitejs/devtools` core probes integrations against the app `cwd`, so under pnpm's isolated layout an app-local install is invisible and the Vitest dock fails with `VTDT0001`. Never move it into an app.

## Monorepo and dev server

- `server.fs.allow: [repoRoot]` (`path.resolve(appDir, "../..")`) for `@repo/*`; leave `server.fs.strict` at its default `true`.
- Vite resolves the `package.json` `"imports"` map (`#/*`) natively: never add `resolve.alias` for it.
- `server.warmup.clientFiles` for hot entry files only. Keep `server.forwardConsole` (or `{ unhandledErrors: true, logLevels: ["warn", "error"] }`) for agentic dev.

## Build, env, deps

- Leave `build.target` unset (Vite 8 default `baseline-widely-available`). `sourcemap`: inline in development mode, `hidden` in production (kept for symbolication, excluded from the assets upload by the generated `.assetsignore`). `reportCompressedSize` is on only for the `analyze` build (`ANALYZE=true`): gzip sizing slows every build, and the `bundle-analyzer` agent reads the gzip column from that build's chunk table. Leave `cssCodeSplit`, `assetsInlineLimit`, and `chunkSizeWarningLimit` at their defaults. Leave `modulePreload.polyfill` at its default `true` unless you intentionally drop older-browser preload support.
- Vendor chunks: react, tanstack-router, tanstack-query, workspace packages, catch-all `node_modules`. HTML gets `Cache-Control: no-cache` through the generated `_headers`.
- Handle `vite:preloadError` in the client entry: reload once per session (sessionStorage guard) so returning users recover from stale chunks after a deploy.
- Fail the production `build` on missing or placeholder required `VITE_*` values; skip that check under static analysis (`knip`).
- `_headers` (cache + CSP) and `.assetsignore` (`*.map`) come from the `generated-build-artifacts` plugin, which `this.emitFile`s them in `generateBundle` for the `client` environment only; never hand-edit them.
- `cf build` writes the Build Output to `.cloudflare/output/v0/`, not `dist/`, with the client build in `workers/default/assets/`, where `sentry:sourcemaps` reads the maps; the only `dist/` file left is the `analyze` build's `dist/stats.html`.
- `optimizeDeps.entries` + `include` for heavy deps tune the dev pre-bundler only, not production bundle size.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.