msw-mock-gen
Version:
A Vite plugin that automatically generates MSW (Mock Service Worker) handlers from your API calls by watching TypeScript/JavaScript files and parsing URL patterns. Supports Vite 2+ and Node.js 12+ for maximum compatibility.
39 lines (38 loc) • 1.3 kB
TypeScript
import type { Plugin } from "vite";
import { MSWMockGenOptions } from "./types";
export type { MSWMockGenOptions, MSWMockGenConfig } from "./types";
/**
* MSW Mock Generator - A Vite plugin that automatically generates MSW (Mock Service Worker) handlers
* from your API calls by watching specified folders and parsing TypeScript/JavaScript files for URL patterns.
*
* @param options - Configuration options for the plugin
* @returns Vite plugin instance
*
* @example
* ```typescript
* // vite.config.ts
* import { defineConfig } from 'vite';
* import mswMockGen from 'msw-mock-gen';
*
* export default defineConfig({
* plugins: [
* mswMockGen({
* configs: [
* {
* watchFolder: 'src/data/queries',
* outputFolder: 'src/data/queries/mocks',
* outputFileName: 'mswHandlers.generated',
* excludePatterns: ['navigate({', 'to: "/'] // Config-specific patterns
* }
* ],
* quiet: true,
* mergeHandlers: true,
* outputFolder: 'src/mocks',
* outputFileName: 'mswHandlers.generated',
* excludePatterns: ['navigate({', 'href: "/'] // Global patterns (applied to all configs)
* })
* ]
* });
* ```
*/
export default function mswMockGen(options?: MSWMockGenOptions): Plugin;