{"id":22744,"library":"vite-plugin-mock-simple","title":"vite-plugin-mock-simple","description":"A lightweight Vite plugin providing local mock APIs during development, with HMR support for mock files. Version 1.0.3 (stable, last release unchanged from 1.0.1) is a TypeScript-based fork of vite-plugin-mock-server with zero dependencies. Supports ant-style path patterns, JSON bodies, custom handlers, and configurable delays. Differentiators: zero external dependencies beyond Vite, simple API using arrays of route definitions, and optional JSON shorthand via `jsonBody`.","status":"maintenance","version":"1.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/reinerBa/vite-plugin-mock-simple","tags":["javascript","vite","mock","hmr","typescript"],"install":[{"cmd":"npm install vite-plugin-mock-simple","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-mock-simple","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-mock-simple","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; plugin runs on Vite >=2.x","package":"vite","optional":false}],"imports":[{"note":"ESM-only; package does not expose CJS require","wrong":"const mockSimple = require('vite-plugin-mock-simple')","symbol":"mockSimple","correct":"import mockSimple from 'vite-plugin-mock-simple'"},{"note":"TypeScript type export","wrong":"","symbol":"MockHandler","correct":"import { MockHandler } from 'vite-plugin-mock-simple'"},{"note":"ConfigOptions is a type; use type import for clarity, though value import also works at runtime","wrong":"import { ConfigOptions } from 'vite-plugin-mock-simple'","symbol":"ConfigOptions","correct":"import type { ConfigOptions } from 'vite-plugin-mock-simple'"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite';\nimport vue from '@vitejs/plugin-vue';\nimport mockSimple from 'vite-plugin-mock-simple';\n\nexport default defineConfig({\n  plugins: [\n    vue(),\n    mockSimple([\n      {\n        pattern: '/api/hello',\n        method: 'GET',\n        handle: (req, res) => {\n          res.setHeader('Content-Type', 'application/json');\n          res.end(JSON.stringify({ message: `Hello from ${req.url}` }));\n        }\n      },\n      {\n        pattern: '/api/data',\n        jsonBody: { foo: 'bar' }\n      },\n      {\n        pattern: '/api/delayed',\n        delay: 500,\n        jsonBody: { status: 'ok' }\n      }\n    ])\n  ]\n});","lang":"typescript","description":"Vite config with mockSimple plugin: three route examples – custom handler, JSON response, and delayed response."},"warnings":[{"fix":"Use either `handle` or `jsonBody` per route definition, not both.","message":"MockHandler interface has mutually exclusive properties: if `jsonBody` is specified, `handle` must not be present; vice versa.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use consistent comma+space separation: 'GET, POST, DELETE'. Trim spaces around methods.","message":"The `method` property supports comma-separated values (e.g., 'GET, POST') but is case-insensitive. However, incorrect spacing (e.g., 'GET,POST') may cause one method to be ignored.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always start pattern with `/` (e.g., `/api/**`).","message":"`pattern` uses ant-style path matcher; wildcards like `**` work, but leading slash is required for path matching. Patterns missing leading slash may never match.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Add `method: 'POST'` or `method: 'GET, POST'` if you need multiple methods.","message":"Default method is GET. If you define a `pattern` without specifying `method`, it only matches GET requests. POST/PUT etc. must be explicitly set.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Ensure package is in devDependencies: `npm i -D vite-plugin-mock-simple`. If type errors persist, add to tsconfig.json compilerOptions.types or skipLibCheck.","cause":"Package is installed as devDependency but not imported correctly, or TypeScript cannot resolve types.","error":"Cannot find module 'vite-plugin-mock-simple' or its corresponding type declarations"},{"fix":"Use default import: `import mockSimple from 'vite-plugin-mock-simple'`.","cause":"Incorrect import style (e.g., using named import `{ mockSimple }` when it's a default export).","error":"TypeError: mockSimple is not a function"},{"fix":"Every route definition must include `pattern` and exactly one of `handle` or `jsonBody`. Example: `{ pattern: '/api/test', jsonBody: {} }`.","cause":"Route object is missing either `handle` or `jsonBody`, or pattern is undefined.","error":"Error: pattern and handle/jsonBody are required for mock route definition"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}