CodeVetter · Repo Unpack · System map
vitejs/vite
Three publishable packages under `packages/`, a 83-directory `playground/` that doubles as the integration test corpus, and a VitePress `docs/` site deployed to Netlify. The `vite` package's runtime splits four ways: `src/node` (server, build, config, plugins — Node only), `src/client` (browser HMR client and error overlay), `src/module-runner` (SSR/runtime module evaluation), and `src/shared` (code compiled into both sides). All bundling — of Vite itself, of user configs, of dep pre-bundles, and of production output — goes through Rolldown; Rollup remains only as a type source and devDependency. There is no database or persistent store; the only on-disk state is the dep-optimizer cache under `cacheDir` and build output under `outDir`.
- The published CLI entry is `packages/vite/bin/vite.js`, a thin launcher that enables source maps, installs an `unhandledRejection` trap, parses `-d/--debug`, `-f/--filter` and `--profile` out of `process.argv` *before* importing `../dist/node/cli.js`, and calls `module.enableCompileCache()` with a 10s `flushCompileCache` timer.
- `packages/vite/src/node/cli.ts` registers exactly four `cac` commands: the default `[root]` (aliased `serve` and `dev`), `build [root]`, `optimize [root]` (marked deprecated in its own description), and `preview [root]`; each dynamically `import()`s its implementation module so the dev path never loads `build.ts`.
- The package's public API surface is `packages/vite/src/node/index.ts`, which re-exports `createServer`, `build`, `createBuilder`, `preview`, `optimizeDeps`, `defineConfig`/`resolveConfig`/`loadConfigFromFile`, `runnerImport`, `fetchModule`, `createServerHotChannel`, `transformWithOxc`, `preprocessCSS`, and `parseAst`/`parseAstAsync` aliased from Rolldown.
- `package.json` `exports` publishes four entry points — `.` → `dist/node/index.js`, `./module-runner` → `dist/node/module-runner.js`, `./internal` → `dist/node/internal.js`, and raw `./dist/client/*` — with `./types/internal/*` explicitly nulled to keep internal types unreachable.
- Vite builds itself with Rolldown, not Rollup: `rolldown.config.ts` emits separate browser bundles for `src/client/env.ts` → `dist/client/env.mjs`, `src/client/clientEntry.ts` → `dist/client/client.mjs`, and `src/client/bundledDevClient.ts` → `dist/client/bundledDevClient.mjs`, plus a Node ESM bundle with `node/[name].js` entries and `node/chunks/` shared chunks.
- The dev server is a `connect()` app, not a framework: `_createServer` builds `middlewares = connect()`, wraps it in `resolveHttpServer`, attaches `createWebSocketServer`, and creates a `chokidar` watcher over root + `config.configFileDependencies` + env files + `publicDir`.
- Runtime state is owned per-environment, not globally: `_createServer` iterates `config.environments` calling `environmentOptions.dev.createEnvironment(name, config, { ws })` and `environment.init({ watcher, previousInstance })`, so each of `client`/`ssr`/custom gets its own `DevEnvironment` with its own `moduleGraph` and `pluginContainer`.
- The legacy flat `server.moduleGraph` / `server.pluginContainer` / `server.transformRequest` APIs still exist but are getters that call `warnFutureDeprecation(config, 'removeServerModuleGraph')` etc. and delegate to the client environment via a `ModuleGraph` facade in `mixedModuleGraph.ts`.
- Production builds go through `createBuilder` → `builder.buildApp()` → per-environment `buildEnvironment()`, which calls `resolveRolldownOptions(environment, chunkMetadataMap)` then `rolldown(...)` and `bundle.write|generate`; `--watch` instead returns a Rolldown `watch()` watcher wired to BUNDLE_START/BUNDLE_END/ERROR events.
- The pnpm workspace spans `packages/*`, `playground/**`, nested `packages/**/__tests__/**`, and `docs`, with `overrides: { vite: 'workspace:*' }` so every playground resolves the local build, and patched deps for `sirv@3.0.2`, `chokidar@3.6.0` and `dotenv-expand@13.0.0`.
- Build/test commands are all at the root: `pnpm build` (`pnpm -r --filter='./packages/*' run build`), `pnpm test` = `test-unit && test-serve && test-build`, plus `test-serve-bundled` which sets `VITE_TEST_BUNDLED_DEV=1`, and `ci-publish` (`tsx scripts/publishCI.ts`).
- Docs are a separate VitePress app (`@vitejs/monorepo-docs`) with a 592-line `docs/.vitepress/config.ts`, deployed by Netlify via `command = "pnpm ci-docs"` publishing `docs/.vitepress/dist`, gated by `scripts/docs-check.sh` as the ignore predicate.
- External integrations are optional peer deps resolved lazily: `sass`/`sass-embedded`/`less`/`stylus`/`sugarss` for CSS, `terser` for minification, `jiti`/`tsx` for config loading, and `@vitejs/devtools` (loaded via `await import('@vitejs/devtools/integration')` inside `builder.runDevTools()`).
- The repo now depends on hosted build-cache infrastructure: `@voidzero-dev/vite-task-client` supplies `disableCache()` (called first thing in `_createServer` because dev output can't be replayed) and `getEnv('NODE_ENV')`/`getEnvs` used during config and env resolution.