Skip to content
FrontDepth, Home

Vite: from request to module

MiddleSenior

Overview

Follow one module through the Vite 8 dev server: the transform middleware, the resolveId, load and transform hooks, import rewriting, and how a file change becomes an HMR update or a full reload.

In development Vite does not bundle your code. The browser asks for each module over HTTP, and the dev server answers by running that one file through a plugin pipeline. This tour follows a module through Vite 8 at the v8.3.8 tag: the middleware that receives the request, the cache in the module graph, the resolveId → load → transform hooks, the import analysis that turns 'nanoid' into a URL — and then what happens when you save a file: how the server chooses between an HMR update and a full reload, and how the browser applies the update.

In Vite 8 all of this runs per environment (the Environment API): the browser is the client environment, with its own module graph and plugin container. The production build (Rolldown), the internals of dependency pre-bundling, CSS, SSR and the experimental bundled dev mode are left out. Every behaviour described was observed in a small sandbox app on a Vite 8.3.8 dev server.

How the pieces connect

Select a box to open the step that explains it. Dashed boxes are mentioned but not covered.

moduleGraph
Connections:
  • transformMiddleware → transformRequest (calls)
  • transformRequest → loadAndTransform (not cached)
  • loadAndTransform → pluginContainer (hooks)
  • pluginContainer → vite:import-analysis (last plugin)
  • vite:import-analysis → moduleGraph (records)
  • updateModules → propagateUpdate (calls)
  • propagateUpdate → moduleGraph (reads importers)
  • updateModules → handleMessage (WebSocket)
  • handleMessage → fetchUpdate (queues)
  • fetchUpdate → transformMiddleware (import(?t=))