A mock plugin for Vite that provides local mock data for development and testing. Current stable version is 3.0.2, with active development and releases. It integrates with Vite's dev server, supports hot module replacement (HMR) for mock files, and allows mocking API requests during development. Differentiated by its tight integration with Vite, TypeScript support, and use of mockjs for data generation. Requires Vite >=4.0.0, esbuild >=0.17, and mockjs >=1.1.0 as peer dependencies.
npm install vite-plugin-mockVerified import paths — ran on the pinned version, not inferred.
Configures vite-plugin-mock in vite.config.ts and creates a simple mock endpoint for /api/user.
Upgrade Vite to >=4.0.0 and Node to >=16.0.0.
Remove 'supportTs' from config; TypeScript is automatically supported.
Set 'mockPath' to the absolute or relative path to your mock directory.
Change 'import vitePluginMock from 'vite-plugin-mock'' to 'import { viteMockServe } from 'vite-plugin-mock''.Place mock files inside the project root or use symlinks.
npm install mockjs --save-dev
Use import { viteMockServe } from 'vite-plugin-mock' or import vitePluginMock from 'vite-plugin-mock'Upgrade Vite to >=4.0.0
Check mockPath in viteMockServe config and ensure the directory exists.