PART 05
Environment API
Multi-environment models beyond client / ssr, framework adapters and RSC-like patterns.
- 5.1Why the Environment APIWhat limitations did Vite's SSR model hit in the multi-framework era? What problem does the Environment API set out to solve, and what is its design intent?
- 5.2Core Concepts: Environment, ModuleRunner, HotChannelThe three core abstractions of the Environment API — what each one is, what problem it solves, and how they work together. Includes a visual component to aid understanding.
- 5.3Default Environments: client and ssrHow are Vite's two built-in default environments configured? What are the differences in their default behavior? How do you customize the resolve rules for each?
- 5.4Custom EnvironmentsBeyond the built-in client and ssr environments, how do you create dedicated environments for Cloudflare Workers, Edge Runtime, and Service Workers? What does the configuration structure for a custom environment look like?
- 5.5DevEnvironment vs BuildEnvironmentThe two states of the Environment API — the dev-time DevEnvironment has a hot channel and module runner; the build-time BuildEnvironment focuses on output generation. What are the API differences between them?
- 5.6ModuleRunner Deep DiveHow does ModuleRunner execute modules inside a specified Environment? What is its internal mechanism? How does it handle HMR, module caching, and circular dependencies?
- 5.7RunnableDevEnvironment vs FetchableDevEnvironmentThe two communication models of the Environment API — in-process direct execution (Runnable) and cross-process HTTP fetching (Fetchable). When should you use each?
- 5.8`buildApp` Hook in PracticeUse the buildApp hook introduced in Vite 7+ to coordinate multi-environment build order — ssr before client, or parallel builds — and how to share build information across environments.
- 5.9Framework Perspective: How Nuxt, SvelteKit, and React Router Use the Env APIHow three major meta-frameworks restructure their SSR and multi-environment support on top of Vite 8's Environment API — understanding the design intent of the Env API from a framework author's point of view.
- 5.10Project 6: RSC-like Multi-Environment Build with the Env APIA comprehensive hands-on project — use Vite 8's Environment API to build an RSC-like three-environment architecture with independent module graphs for client/ssr/rsc, and use ModuleRunner to pass data across environments.