A fake server plugin for Vite that intercepts HTTP requests (XHR and Fetch) to return mock data during development or production. Version 3.0.18, actively maintained with frequent releases (last update ~1 month ago). Supports ESM/CJS, TypeScript type hints via defineFakeRoute, multiple file types (ts, js, mjs, cjs, mts, cts), and both HTTP/1 and HTTP/2. No built-in mock library dependency – works with @faker-js/faker, mockjs, or custom responses. Features include custom response headers/status, timeout simulation, raw response handling, and production build export. Interception is powered by XHook, which has known Firefox issues (see warnings).
npm install vite-plugin-fake-server-turboVerified import paths — ran on the pinned version, not inferred.
Sets up vite-plugin-fake-server with a Vite config, defines a fake route for /mock/get-user-info, and intercepts the request at runtime.
Use import { defineFakeRoute } from 'vite-plugin-fake-server/client'Upgrade to v2.2.2+ which includes a workaround for Firefox XHR payload issue
Do not use this plugin for server-side mock data; rely on standard mocking libraries like vitest-fetch-mock for Node tests
Ensure your glob patterns are compatible with tinyglobby (e.g., {**/*.fake.ts} works, but some fast-glob extensions might fail)Use named import: import { vitePluginFakeServer } from 'vite-plugin-fake-server'Import from 'vite-plugin-fake-server/client' instead
Rename to .mjs or .mts, or set "type": "module" in package.json, or use CommonJS syntax (module.exports) in .cjs files