Skip to content

Commit 06df4af

Browse files
committed
feat: add enabled plugin options
1 parent 475f128 commit 06df4af

8 files changed

Lines changed: 43 additions & 0 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ export default defineMock({
187187

188188
## Plugin Options
189189

190+
### enabled
191+
192+
- **Type:** `boolean`
193+
- **Default:** `true`
194+
- **Details:**
195+
196+
Whether to enable mock server, if set to `false`, the plugin will not work.
197+
190198
### prefix
191199

192200
- **Type:** `string | string[]`

README.zh-CN.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ export default defineMock({
188188

189189
## Plugin Options
190190

191+
### enabled
192+
193+
- **类型:** `boolean`
194+
- **默认值:** `true`
195+
- **详情:**
196+
197+
是否开启 mock 服务。如果设置为 `false`,插件将不会生效。
198+
191199
### prefix
192200

193201
- **类型:** `string | string[]`

docs/en/api/mock-server-plugin-options.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Plugin configuration options interface, used to configure the behavior of Mock D
66

77
```ts
88
interface MockServerPluginOptions {
9+
enabled?: boolean
910
prefix?: string | string[]
1011
wsPrefix?: string | string[]
1112
cwd?: string
@@ -25,6 +26,12 @@ interface MockServerPluginOptions {
2526

2627
## Property Details
2728

29+
### enabled
30+
31+
- **Type**: `boolean`
32+
- **Default**: `true`
33+
- **Description**: Whether to enable Mock server, if set to `false`, the plugin will not work.
34+
2835
### prefix
2936

3037
- **Type**: `string | string[]`

docs/en/guide/plugin-config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default defineConfig({
2323

2424
| Configuration | Type | Default | Description |
2525
| ------------- | ---- | ------- | ----------- |
26+
| [enabled](../api/mock-server-plugin-options#enabled) | `boolean` | `true` | Whether to enable Mock server |
2627
| [prefix](../api/mock-server-plugin-options#prefix) | `string \| string[]` | `[]` | HTTP Mock path prefix |
2728
| [wsPrefix](../api/mock-server-plugin-options#wsprefix) | `string \| string[]` | `[]` | WebSocket path prefix |
2829
| [cwd](../api/mock-server-plugin-options#cwd) | `string` | `process.cwd()` | Working directory |

docs/zh/api/mock-server-plugin-options.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
```ts
88
interface MockServerPluginOptions {
9+
enabled?: boolean
910
prefix?: string | string[]
1011
wsPrefix?: string | string[]
1112
cwd?: string
@@ -27,6 +28,12 @@ interface MockServerPluginOptions {
2728

2829
## 属性详解
2930

31+
### enabled
32+
33+
- **类型**: `boolean`
34+
- **默认值**: `true`
35+
- **描述**: 是否开启 Mock 服务,设置为 `false` 时插件将不生效。
36+
3037
### prefix
3138

3239
- **类型**: `string | string[]`

docs/zh/guide/plugin-config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default defineConfig({
2323

2424
| 配置项 | 类型 | 默认值 | 说明 |
2525
| ------ | ---- | ------ | ---- |
26+
| [enabled](../api/mock-server-plugin-options#enabled) | `boolean` | `true` | 是否开启 Mock 服务 |
2627
| [prefix](../api/mock-server-plugin-options#prefix) | `string \| string[]` | `[]` | HTTP Mock 路径前缀 |
2728
| [wsPrefix](../api/mock-server-plugin-options#wsprefix) | `string \| string[]` | `[]` | WebSocket 路径前缀 |
2829
| [cwd](../api/mock-server-plugin-options#cwd) | `string` | `process.cwd()` | 工作目录 |

vite-plugin-mock-dev-server/src/core/plugin.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import { resolvePluginOptions, resolveRecordOptions } from './options'
1818
* @returns Array of Vite plugin objects / Vite 插件对象数组
1919
*/
2020
export function mockDevServerPlugin(options: MockServerPluginOptions = {}): Plugin[] {
21+
if (options.enabled === false)
22+
return []
23+
2124
const plugins: Plugin[] = [serverPlugin(options)]
2225
if (options.build)
2326
plugins.push(buildPlugin(options))

vite-plugin-mock-dev-server/src/types/options.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ export interface MockServerPluginOptions {
148148
*/
149149
wsPrefix?: string | string[]
150150

151+
/**
152+
* Whether to enable mock server
153+
*
154+
* 是否开启 mock 服务
155+
* @default true
156+
*/
157+
enabled?: boolean
158+
151159
/**
152160
* Configure the matching context for `include` and `exclude`.
153161
*

0 commit comments

Comments
 (0)