Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/en/examples/websocket.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<<< @/../example/mock/ws.mock.ts

## Simulated Real-time Push
## Real-time Push

::: code-group

Expand Down Expand Up @@ -32,7 +32,7 @@ export default defineMock({

:::

## Simulated Chat Room
## Chat Room

::: code-group

Expand Down
6 changes: 5 additions & 1 deletion docs/en/guide/define-mock.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Mock configuration type helper function

## Usage

```ts
::: code-group

```ts [*.mock.ts]
import { defineMock } from 'vite-plugin-mock-dev-server'

export default defineMock({
Expand All @@ -13,6 +15,8 @@ export default defineMock({
})
```

:::

Pass in an array:

```ts
Expand Down
8 changes: 5 additions & 3 deletions docs/en/guide/introduce.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ It uses the built-in `http` and `http-proxy` services of Vite to intercept the p

You can use any third-party module in the mock configuration file with `node`. This means that you can use libraries like `mockjs` / `faker-js` to help generate mock data.

The plugin supports responding with multiple data types including `text` / `json` / `Buffer` / `ReadStream`, and also supports setting headers and cookies.
The plugin supports responding to various data types including `text/json/Buffer/ReadStream`, and also supports setting headers, cookies, etc.

The plugin also supports simulating `WebSocket`, making it easy to debug `WebSocket` services in local development environment.
The plugin supports simulating `WebSocket`, making it easy to debug `WebSocket` services in a local development environment.

The plugin also supports simulating `Server-Sent Events`, making it easy to debug `EventSource` in a local development environment.

## Features

Expand All @@ -29,5 +31,5 @@ The plugin also supports simulating `WebSocket`, making it easy to debug `WebSoc
- 🌈 Support `vite preview` mode.
- 📤 Support `multipart` content-type, mock upload file.
- 📥 Support mock download file.
- ⚜️ Support `WebSocket Mock`
- ⚜️ Support `WebSocket Mock`、`Server-Sent Events`
- 🗂 Support building small independent deployable mock services.
7 changes: 6 additions & 1 deletion docs/en/guide/mock-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

`type: MockOptionsItem | MockOptionsItem[]`

```ts
::: code-group

```ts [*.mock.ts]
import { defineMock } from 'vite-plugin-mock-dev-server'

export default defineMock({
Expand All @@ -11,6 +13,8 @@ export default defineMock({
})
```

:::

**Type Definition:**

```ts
Expand Down Expand Up @@ -124,6 +128,7 @@ The actual `content-type` is determined internally by the plugin using `mime-typ
- **Default**:

The default value is determined based on the value of [type](#type):

| Type | Default |
| -------- | -------------------------------------------------------- |
| `text` | `{ 'Content-Type': 'text/plain' }` |
Expand Down
6 changes: 5 additions & 1 deletion docs/en/guide/mock-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Vite Plugin Function

## Usage

``` ts
::: code-group

``` ts [vite.config.ts]
import { defineConfig } from 'vite'
import mockDevServerPlugin from 'vite-plugin-mock-dev-server'

Expand All @@ -15,6 +17,8 @@ export default defineConfig({
})
```

:::

## `options`

`type: MockServerPluginOptions`
Expand Down
6 changes: 5 additions & 1 deletion docs/guide/define-mock.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ mock配置 类型帮助函数

## 使用

```ts
::: code-group

```ts [*.mock.ts]
import { defineMock } from 'vite-plugin-mock-dev-server'

export default defineMock({
Expand All @@ -13,6 +15,8 @@ export default defineMock({
})
```

:::

传入数组:

```ts
Expand Down
8 changes: 5 additions & 3 deletions docs/guide/introduce.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

你可以在 mock配置文件中使用`node` 任意第三方模块。 这表示,你可以使用如 `mockjs` / `faker-js` 等库帮助生成 `mock data`。

插件支持响应多种数据类型包括 `text/json/Buffer/ReadStream`等,还支持设置 headers、cookies。
插件支持响应多种数据类型包括 `text/json/Buffer/ReadStream`等,还支持设置 headers、cookies

插件还支持模拟 `WebSocket`,可以轻松的实现在本地开发环境调试 `WebSocket` 服务。
插件支持模拟 `WebSocket`,可以轻松的实现在本地开发环境调试 `WebSocket` 服务。

插件还支持 模拟 `Server-Sent Events`,可以轻松的实现在本地开发环境调试 `EventSource` 。

## 特性

Expand All @@ -29,5 +31,5 @@
- 🌈 支持 `vite preview` 模式
- 📤 支持 multipart 类型,模拟文件上传
- 📥 支持模拟文件下载
- ⚜️ 支持模拟 `WebSocket`
- ⚜️ 支持模拟 `WebSocket`、 `Server-Sent Events`
- 🗂 支持构建可独立部署的小型mock服务
7 changes: 6 additions & 1 deletion docs/guide/mock-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

`type: MockOptionsItem | MockOptionsItem[]`

```ts
::: code-group

```ts [*.mock.ts]
import { defineMock } from 'vite-plugin-mock-dev-server'

export default defineMock({
Expand All @@ -11,6 +13,8 @@ export default defineMock({
})
```

:::

**类型定义:**

```ts
Expand Down Expand Up @@ -125,6 +129,7 @@ export default defineMock({
- **默认值**:

默认值根据 [type](#type) 的值确定:

| type | 默认值 |
| -------- | ------------------------------------------------- |
| `text` | `{ 'Content-Type': 'text/plain' }` |
Expand Down
6 changes: 5 additions & 1 deletion docs/guide/mock-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Vite Plugin Function

## 使用

``` ts
::: code-group

``` ts [vite.config.ts]
import { defineConfig } from 'vite'
import mockDevServerPlugin from 'vite-plugin-mock-dev-server'

Expand All @@ -15,6 +17,8 @@ export default defineConfig({
})
```

:::

## `options`

`type: MockServerPluginOptions`
Expand Down
1 change: 1 addition & 0 deletions docs/public/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion plugin/src/core/defineMockData.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* 由于插件是 分别独立对 `*.mock.*` 等文件作为单独入口进行编译的,
* 这导致了 mock 文件编译后的依赖关系不一致,每个 mock 文件拥有独立的作用域,
* 使得即使多个 `*.mock.*` 虽然引入了同一个 `data.ts` 文件,然而确实完全不同两份 `data`,
* 使得即使多个 `*.mock.*` 虽然引入了同一个 `data.ts` 文件,然而确是完全不同两份 `data`,
* 使得对 `data` 的操作,在不同的 `*.mock.*` 文件中并不能共享。
*
* 为此,插件提供了一种基于 memory 的数据共享机制。
Expand Down