A Vite plugin that provides a file-based mock API using JSON files during development. Version 0.6.2 (Feb 2025) is the latest stable release, published under MIT license. It offers zero-config CRUD endpoints from JSON files placed in a 'mock' directory, with built-in pagination, sorting, filtering (including operators like ne, lt, gt), and OpenAPI/Swagger UI support. Unlike heavier mock servers, it integrates directly into Vite's dev server, requires no database, and ships TypeScript types. It also serves static files and allows custom route handlers. Node >=15.7.0 required; Vite ^4.0.0 peer dependency.
npm install vite-plugin-simple-json-serverVerified import paths — ran on the pinned version, not inferred.
Minimal setup for file-based mock API with Vite, including CRUD, pagination, sorting, filtering.
Use HEAD /collection or /collection?filter=value to get count via X-Total-Count header instead of ?count=true.
Rename option from 'mockRootDir' to 'mockDir' in vite config.
Ensure non-array JSON files are not accidentally mutated via POST/PUT/PATCH requests if unintended; consider adding custom handlers or restricting methods.
Double-check field names in query parameters; use exact field names from the JSON data.
Ensure mock JSON files for collection endpoints are arrays of objects; for single resources, use object files without array wrapper.
Use Vite 4.x; check latest version for Vite 5 support.
Downgrade Vite to 4.x, or wait for plugin update that supports Vite 5.
Use import statement (native ESM) or enable experimental ESM support in Node.
Ensure all JSON files are valid and start with '[' or '{'. Remove BOM characters.