Plugin Configuration
Plugin configuration is used to control the overall behavior of Mock Dev Server.
Basic Structure
ts
import { defineConfig } from 'vite'
import { mockDevServerPlugin } from 'vite-plugin-mock-dev-server'
export default defineConfig({
plugins: [
mockDevServerPlugin({
prefix: ['/api'],
dir: 'mock',
log: 'info'
})
]
})Configuration Overview
| Configuration | Type | Default | Description |
|---|---|---|---|
| enabled | boolean | true | Whether to enable Mock server |
| prefix | string | string[] | [] | HTTP Mock path prefix |
| wsPrefix | string | string[] | [] | WebSocket path prefix |
| cwd | string | process.cwd() | Working directory |
| dir | string | 'mock' | Mock file directory |
| include | string | string[] | ['**/*.mock.{js,ts,cjs,mjs,json,json5}'] | Included file patterns |
| exclude | string | string[] | ['**/node_modules/**'] | Excluded file patterns |
| reload | boolean | false | Refresh page on hot update |
| log | boolean | LogLevel | 'info' | Log level |
| cors | boolean | CorsOptions | true | CORS configuration |
| formidableOptions | formidable.Options | - | File upload configuration |
| cookiesOptions | Cookies.Option | - | Cookie configuration |
| bodyParserOptions | BodyParserOptions | - | Request body parsing configuration |
| build | boolean | ServerBuildOption | false | Build standalone service |
| record | boolean | RecordOption | false | Request recording configuration |
| replay | boolean | ReplayOption | false | Request playback configuration |
| priority | MockMatchPriority | - | Matching priority configuration |
Detailed Documentation
View API Reference - MockServerPluginOptions for complete configuration item descriptions and examples.
