Skip to content

Commit ae04539

Browse files
authored
Merge pull request #69 from pengzhanbo/lint_and_esm
markdown lint fix & compiler
2 parents 2986210 + b3f5ae9 commit ae04539

27 files changed

+580
-837
lines changed

README.md

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,21 @@
88

99
<br>
1010
<p align="center">
11-
<a href="https://www.npmjs.com/package/vite-plugin-mock-dev-server"><img alt="npm" src="https://img.shields.io/npm/v/vite-plugin-mock-dev-server?style=flat-square"></a>
12-
<img alt="node-current" src="https://img.shields.io/node/v/vite-plugin-mock-dev-server?style=flat-square">
13-
<img alt="npm peer dependency version" src="https://img.shields.io/npm/dependency-version/vite-plugin-mock-dev-server/peer/vite?style=flat-square">
14-
<img alt="npm" src="https://img.shields.io/npm/dt/vite-plugin-mock-dev-server?style=flat-square">
15-
<br>
16-
<img alt="GitHub Workflow Status" src="https://img.shields.io/github/actions/workflow/status/pengzhanbo/vite-plugin-mock-dev-server/lint.yml?style=flat-square">
17-
<a href="https://app.fossa.com/projects/git%2Bgithub.com%2Fpengzhanbo%2Fvite-plugin-mock-dev-server?ref=badge_shield"><img alt="fossa status" src="https://app.fossa.com/api/projects/git%2Bgithub.com%2Fpengzhanbo%2Fvite-plugin-mock-dev-server.svg?type=shield"></a>
11+
<a href="https://www.npmjs.com/package/vite-plugin-mock-dev-server"><img alt="npm" src="https://img.shields.io/npm/v/vite-plugin-mock-dev-server?style=flat-square"></a>
12+
<img alt="node-current" src="https://img.shields.io/node/v/vite-plugin-mock-dev-server?style=flat-square">
13+
<img alt="npm peer dependency version" src="https://img.shields.io/npm/dependency-version/vite-plugin-mock-dev-server/peer/vite?style=flat-square">
14+
<img alt="npm" src="https://img.shields.io/npm/dt/vite-plugin-mock-dev-server?style=flat-square">
15+
<br>
16+
<img alt="GitHub Workflow Status" src="https://img.shields.io/github/actions/workflow/status/pengzhanbo/vite-plugin-mock-dev-server/lint.yml?style=flat-square">
17+
<a href="https://app.fossa.com/projects/git%2Bgithub.com%2Fpengzhanbo%2Fvite-plugin-mock-dev-server?ref=badge_shield"><img alt="fossa status" src="https://app.fossa.com/api/projects/git%2Bgithub.com%2Fpengzhanbo%2Fvite-plugin-mock-dev-server.svg?type=shield"></a>
1818
</p>
1919
<br>
2020
<p align="center">
21-
<span>English</span> | <a href="/README.zh-CN.md">简体中文</a>
21+
<span>English</span> | <a href="/README.zh-CN.md">简体中文</a>
2222
</p>
2323
<br>
2424
<br>
2525

26-
2726
## Feature
2827

2928
- ⚡️ Lightweight, Flexible, Fast.
@@ -46,7 +45,6 @@
4645
- ⚜️ Support `WebSocket Mock`
4746
- 🗂 Support building small independent deployable mock services.
4847

49-
5048
## Documentation
5149

5250
See the [documentation](https://vite-plugin-mock-dev-server.netlify.app/en/) to learn more.
@@ -60,7 +58,7 @@ See the [documentation](https://vite-plugin-mock-dev-server.netlify.app/en/) to
6058
``` sh
6159
# npm
6260
npm i -D vite-plugin-mock-dev-server
63-
# yarn
61+
# yarn
6462
yarn add vite-plugin-mock-dev-server
6563
# pnpm
6664
pnpm add -D vite-plugin-mock-dev-server
@@ -114,7 +112,6 @@ export default defineMock({
114112

115113
Vite plugin
116114

117-
118115
`vite.config.ts`
119116
``` ts
120117
import { defineConfig } from 'vite'
@@ -127,21 +124,20 @@ export default defineConfig({
127124
})
128125
```
129126

130-
131127
#### options
132128

133129
- `options.prefix`
134130

135131
**Type:** `string | string[]`
136-
132+
137133
Configure custom matching rules for the mock server. Any request path starting with the value of `prefix` will be proxied to the corresponding target. If the `prefix` value starts with ^, it will be recognized as a RegExp.
138134

139135
> In general, `server.proxy` is sufficient to meet the needs. Adding this item is for compatibility with certain scenarios.
140136
141137
**Default:** `[]`
142138

143139
- `options.wsPrefix`
144-
140+
145141
**Type:** `string | string[]`
146142

147143
Configure the matching rules for the WebSocket service. Any request path starting with the value of `wsPrefix` and using the `ws/wss` protocol will be proxied to the corresponding target.
@@ -151,48 +147,46 @@ export default defineConfig({
151147
> Different from using `viteConfig.server.proxy` by default for http mock, `websocket mock` does not use the ws-related configuration in `viteConfig.server.proxy`. Also, rules configured in `wsPrefix` cannot be configured simultaneously in `viteConfig.server.proxy`, as it will cause conflicts when starting the vite server because multiple instances of WebSocketServer cannot be implemented for the same request.
152148
> This conflict is neither a problem with Vite nor with the plugin; it belongs to a reasonable error type. When switching between WebSocket Mock and WebSocket Proxy, please pay attention to avoid duplicate configurations that may cause conflicts.
153149
154-
155-
- `option.include`
150+
- `option.include`
156151

157152
**Type:** `string | string[]`
158-
153+
159154
Configure to read mock files, which can be a directory, glob, or an array.
160155

161156
**Default:** `['mock/**/*.mock.{js,ts,cjs,mjs,json,json5}']` (Relative to the root directory.)
162157

163158
- `options.exclude`
164159

165160
**Type:** `string | string[]`
166-
161+
167162
When reading mock files for configuration, the files that need to be excluded can be a directory, glob, or array.
168163

169164
**Default:** `['**/node_modules/**','**/.vscode/**','**/.git/**']`
170165

171166
- `options.reload`
172-
167+
173168
**Type:** `boolean`
174169

175170
When the mock resource is hot updated, only the data content is updated, but the page is not refreshed by default. If you want to refresh the page every time you modify the mock file, you can open this option.
176171

177172
- `options.cors`
178-
173+
179174
**Type:** `boolean | CorsOptions`
180175

181176
Enable by default.
182177

183178
Configure to `cors`, see [cors](https://github.com/expressjs/cors#configuration-options)
184179

185-
186180
**Default:** `true`
187181

188182
- `options.log`
189-
183+
190184
**Type:** `boolean | 'info' | 'warn' | 'error' | 'silent'`
191185

192186
Enable log and configure log level.
193187

194188
- `options.formidableOptions`
195-
189+
196190
Configure to `formidable`, see [formidable options](https://github.com/node-formidable/formidable#options)
197191

198192
**Default:** `{}`
@@ -207,7 +201,7 @@ export default defineConfig({
207201
```
208202

209203
- `options.cookiesOptions`
210-
204+
211205
Configure to `cookies`, see [cookies](https://github.com/pillarjs/cookies#new-cookiesrequest-response--options)
212206

213207
**Default:** `{}`
@@ -216,7 +210,7 @@ export default defineConfig({
216210

217211
The configuration needed to build a small, independently deployable mock service.
218212

219-
**Type:** `boolean | ServerBuildOptions`
213+
**Type:** `boolean | ServerBuildOptions`
220214

221215
**Default:** `false`
222216

@@ -241,7 +235,7 @@ export default defineConfig({
241235
```
242236

243237
- `options.priority`
244-
238+
245239
Custom path matching rule priority。[read more](#Custom-Path-Matching-Priority)
246240

247241
**Default:** `undefined`
@@ -473,11 +467,10 @@ type Response = http.ServerResponse<http.IncomingMessage> & {
473467
}
474468
```
475469
476-
477470
> **Tips:**
478-
>
479-
> If you write mock files using json/json5,
480-
> the 'response' method is not supported,
471+
>
472+
> If you write mock files using json/json5,
473+
> the 'response' method is not supported,
481474
> as is the function form that uses other fields.
482475
483476
## Share Mock Data
@@ -525,8 +518,8 @@ export default defineMock([
525518
```
526519

527520
> **Tips:**
528-
>
529-
> The `defineMockData` function relies solely on the shared data support provided by `memory`.
521+
>
522+
> The `defineMockData` function relies solely on the shared data support provided by `memory`.
530523
> If persistent mock data is required, it is recommended to use a `nosql` database like `lowdb` or `level`.
531524
532525
## Custom-Path-Matching-Priority
@@ -576,7 +569,6 @@ export default defineConfig({
576569
> you can use static rules instead of `priority`,
577570
> as static rules always have the highest priority.
578571
579-
580572
## Example
581573

582574
`mock/**/*.mock.{ts,js,mjs,cjs,json,json5}`
@@ -598,7 +590,6 @@ export default defineMock({
598590
})
599591
```
600592

601-
602593
**exp:** Only Support `GET` Method
603594
``` ts
604595
export default defineMock({
@@ -627,7 +618,6 @@ export default defineMock({
627618
})
628619
```
629620

630-
631621
**exp:** Define multiple mock requests for the same URL and match valid rules with validators
632622
``` ts
633623
export default defineMock([
@@ -662,7 +652,6 @@ export default defineMock([
662652
])
663653
```
664654

665-
666655
**exp:** Response Delay
667656
``` ts
668657
export default defineMock({
@@ -671,7 +660,6 @@ export default defineMock({
671660
})
672661
```
673662

674-
675663
**exp:** The interface request failed
676664
``` ts
677665
export default defineMock({
@@ -681,7 +669,6 @@ export default defineMock({
681669
})
682670
```
683671

684-
685672
**exp:** Dynamic route matching
686673
``` ts
687674
export default defineMock({
@@ -749,7 +736,6 @@ export default defineMock({
749736
```
750737
You need install `mockjs`
751738

752-
753739
**exp:** Use `response` to customize the response
754740
``` ts
755741
export default defineMock({
@@ -769,7 +755,6 @@ export default defineMock({
769755
})
770756
```
771757

772-
773758
**exp:** Use json / json5
774759
``` json
775760
{
@@ -780,16 +765,14 @@ export default defineMock({
780765
}
781766
```
782767

783-
784-
785768
**exp:** multipart, upload files.
786769

787770
use [`formidable`](https://www.npmjs.com/package/formidable#readme) to support.
788771
``` html
789772
<form action="/api/upload" method="post" enctype="multipart/form-data">
790773
<p>
791774
<span>file: </span>
792-
<input type="file" name="files" multiple>
775+
<input type="file" name="files" multiple="multiple">
793776
</p>
794777
<p>
795778
<span>name:</span>
@@ -801,7 +784,7 @@ use [`formidable`](https://www.npmjs.com/package/formidable#readme) to support.
801784
</form>
802785
```
803786

804-
fields `files` mapping to `formidable.File`
787+
fields `files` mapping to `formidable.File`
805788
``` ts
806789
export default defineMock({
807790
url: '/api/upload',
@@ -948,5 +931,4 @@ You can access related `mock` interfaces through `localhost:8080/`.
948931

949932
[MIT](/LICENSE)
950933

951-
952934
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fpengzhanbo%2Fvite-plugin-mock-dev-server.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fpengzhanbo%2Fvite-plugin-mock-dev-server?ref=badge_large)

0 commit comments

Comments
 (0)