vite-plugin-mock-dev-server 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,21 +26,21 @@
26
26
 
27
27
  ## Feature
28
28
 
29
- - ⚡️ light weight,flexible,fast
30
- - 🧲 Non - injection, no intrusion to client code
31
- - 💡 ESModule/commonjs
32
- - 🦾 Typescript
33
- - 🏷 Support json / json5
34
- - 📦 Auto import mock file
29
+ - ⚡️ light weight,flexible,fast.
30
+ - 🧲 Not injection-based, non-intrusive to client code.
31
+ - 💡 ESModule/commonjs.
32
+ - 🦾 Typescript.
33
+ - 🏷 Support `json` / `json5`.
34
+ - 📦 Auto import mock file.
35
35
  - 🎨 Support any lib,like `mockjs`,or not use it.
36
- - 📥 Path rules match and request parameters match
36
+ - 📥 Path rule matching, request parameter matching.
37
37
  - ⚙️ Support Enabled/Disabled any one of api mock
38
38
  - 🔥 HMR
39
39
  - ⚖️ Use `server.proxy`
40
40
  - 🍕 Support `viteConfig.define` in mock file
41
41
  - 📤 Support `multipart` content-type,mock upload file.
42
42
  - 🌈 Support `vite preview` mode
43
- - 🗂 Support for building independently deployed mock services
43
+ - 🗂 Support building small independent deployable mock services.
44
44
 
45
45
 
46
46
  ## Documentation
@@ -77,6 +77,7 @@ export default defineConfig({
77
77
  plugins: [
78
78
  mockDevServerPlugin(),
79
79
  ],
80
+ // The fields defined here can also be used in mock.
80
81
  define: {},
81
82
  server: {
82
83
  proxy: {
@@ -87,15 +88,17 @@ export default defineConfig({
87
88
  }
88
89
  })
89
90
  ```
90
- The plugin reads the configuration for `server.proxy` or `options.prefix` and enables mock matching.
91
+ The plugin will read the configuration of `server.proxy` or `options.prefix`, and enable mock matching for matched URLs.
91
92
 
92
- The plugin also reads the `define` configuration and supports direct use in mock files.
93
+ The plugin will also read the `define` configuration, which supports direct use in mock files.
93
94
 
94
- > In a general case, we only need to mock the url with the proxy so that we can proxy and mock through the http service provided by vite, but you can also configure the mock using 'options.prefix'
95
+ > Because in general scenarios, we only need to mock URLs with proxies so that we can use the proxy and mock services provided by Vite's HTTP service.
96
+ >
97
+ > However, you can also configure mocks using `options.prefix`.
95
98
 
96
99
  ### Edit Mock File
97
100
 
98
- By default, write mock data in the `mock` directory of your project root:
101
+ By default, write mock data in the `mock` directory of your project's root directory:
99
102
 
100
103
  `mock/api.mock.ts` :
101
104
  ```ts
@@ -135,9 +138,9 @@ export default defineConfig({
135
138
 
136
139
  **Type:** `string | string[]`
137
140
 
138
- Configure custom matches rules for the mock server. Any requests that request path starts with that `prefix` will be proxied to that specified target. If the `prefix` starts with ^, it will be interpreted as a RegExp.
141
+ Configure custom matching rules for 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.
139
142
 
140
- > In general, `server.proxy` is sufficient to meet the requirements, and this options is added to be compatible with some scenarios.
143
+ > In general, `server.proxy` is sufficient to meet the needs. Adding this item is for compatibility with certain scenarios.
141
144
 
142
145
  **Default:** `[]`
143
146
 
@@ -145,25 +148,22 @@ export default defineConfig({
145
148
 
146
149
  **Type:** `string | string[]`
147
150
 
148
- Configure to read mock files, which can be a directory, glob, or array
151
+ Configure to read mock files, which can be a directory, glob, or an array.
149
152
 
150
- **Default:** `['mock/**/*.mock.{js,ts,cjs,mjs,json,json5}']` (relative for `process.cwd()`)
153
+ **Default:** `['mock/**/*.mock.{js,ts,cjs,mjs,json,json5}']` (Relative to the root directory.)
151
154
 
152
155
  - `options.exclude`
153
156
 
154
157
  **Type:** `string | string[]`
155
158
 
156
- When you configure the mock files to be read, the files you want to exclude can be a directory, glob, or array
159
+ When reading mock files for configuration, the files that need to be excluded can be a directory, glob, or an array.
157
160
 
158
161
  **Default:**
159
162
  ```ts
160
163
  [
161
164
  '**/node_modules/**',
162
- '**/test/**',
163
- 'src/**',
164
165
  '**/.vscode/**',
165
166
  '**/.git/**',
166
- '**/dist/**'
167
167
  ]
168
168
  ```
169
169
 
@@ -171,8 +171,7 @@ export default defineConfig({
171
171
 
172
172
  **Type:** `boolean`
173
173
 
174
- When mock resources are hot reload, only the data content is updated, but the page is not refreshed by default.
175
- Turn this on when you want to refresh the page every time you modify the mock file.
174
+ 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.
176
175
 
177
176
 
178
177
  **Default:** `false`
@@ -194,7 +193,7 @@ export default defineConfig({
194
193
 
195
194
  - `options.build`
196
195
 
197
- When building a small, independently deployable mock service.
196
+ Configuration needed to build a small, independently deployable mock service.
198
197
 
199
198
  **Type:** `boolean | ServerBuildOptions`
200
199
 
@@ -233,11 +232,11 @@ export default defineMock({
233
232
  ```ts
234
233
  export default defineMock({
235
234
  /**
236
- * Address of request,and support like `/api/user/:id`
235
+ * Request address, supports the `/api/user/:id` format.
237
236
  */
238
237
  url: '/api/test',
239
238
  /**
240
- * The request method supported by the API
239
+ * Supported request methods of the interface.
241
240
  *
242
241
  * @type string | string[]
243
242
  * @default ['POST','GET']
@@ -245,16 +244,17 @@ export default defineMock({
245
244
  */
246
245
  method: ['GET', 'POST'],
247
246
  /**
248
- * enable/disable the current mock request
249
- *
250
- * we typically only need a few mock interfaces to work.
251
- * set `false` to disable current mock
247
+ * In practical scenarios,
248
+ * we usually only need certain mock interfaces to take effect,
249
+ * rather than enabling all mock interfaces.
250
+ * For interfaces that do not currently require mocking,
251
+ * they can be set to false.
252
252
  *
253
253
  * @default true
254
254
  */
255
255
  enable: true,
256
256
  /**
257
- * response delay unitms
257
+ * Set interface response delay, unit: ms.
258
258
  *
259
259
  * @default 0
260
260
  */
@@ -270,27 +270,23 @@ export default defineMock({
270
270
  */
271
271
  statusText: 'OK',
272
272
  /**
273
- * Request a validator, through which the mock data
274
- * is returned, otherwise not the current mock.
275
- * In some scenarios where an interface needs to
276
- * return different data through different inputs,
277
- * the validator can solve this kind of problem well.
278
- * It divides the same url into multiple mock
279
- * configurations and determines which mock configuration
280
- * is valid according to the validator.
273
+ * Request validator, return mock data if validated, otherwise do not use current mock.
274
+ * This is useful in scenarios where an interface needs to return different data based
275
+ * on different input parameters.
276
+ * Validators can solve this type of problem well by dividing the same URL into multiple
277
+ * mock configurations and determining which one is effective based on the validator.
281
278
  *
282
279
  * @type { headers?: object; body?: object; query?: object; params?: object; refererQuery?: object }
283
280
  *
284
- * If the validator incoming is an object,
285
- * then the validation method is the comparison of the
286
- * strict request of interface, headers/body/query/params
287
- * each `key-value` congruent, congruent check through
281
+ * If the validator passes in an object,
282
+ * then the validation method is to strictly compare whether the `value`
283
+ * of each `key` in headers/body/query/params in the request interface is exactly equal.
284
+ * If they are all equal, then the validation passes.
288
285
  *
289
286
  * @type ({ headers: object; body: object; query: object; params: object; refererQuery: object }) => boolean
290
- * If the validator is passed a function,
291
- * it takes the requested interface-related data as an input,
292
- * gives it to the consumer for custom validation,
293
- * and returns a boolean
287
+ * If the validator passed in is a function,
288
+ * then the data related to the requested interface will be provided as input parameters
289
+ * for users to perform custom validation and return a boolean.
294
290
  *
295
291
  */
296
292
  validator: {
@@ -299,9 +295,9 @@ export default defineMock({
299
295
  query: {},
300
296
  params: {},
301
297
  /**
302
- * refererQuery validates the query in the url of the page from which the request originated,
303
- * which makes it possible to modify parameters directly in the browser address bar to get
304
- * different mock data
298
+ * refererQuery validates the query parameters in the URL of the request source page,
299
+ * which allows for direct modification of parameters in the browser address bar
300
+ * to obtain different simulated data.
305
301
  */
306
302
  refererQuery: {}
307
303
  },
@@ -329,9 +325,11 @@ export default defineMock({
329
325
  body: {},
330
326
 
331
327
  /**
332
- * If the mock requirement cannot be addressed with the body configuration,
333
- * Then you can expose the http server interface by configuring response,
334
- * Achieve fully controlled custom configuration.
328
+ * If the mock requirement cannot be solved through `body` configuration,
329
+ * then it can be achieved by configuring response and exposing the interface of http server
330
+ * to realize fully controllable custom configuration in req parameters.
331
+ * The parsing of query, body and params has been built-in, so you can use them directly.
332
+ * Don't forget to return response data through `res.end()` or skip mock by calling `next()`.
335
333
  */
336
334
  response(req, res, next) {
337
335
  res.end()
@@ -558,11 +556,11 @@ export default defineMock({
558
556
 
559
557
  ## Mock Services
560
558
 
561
- In some scenarios, you may need to use the data support provided by the mock service for display purposes, but it is possible that the project has been packaged and deployed as a build and is out of the mock service support provided by `vite` and this plugin. Since this plugin was designed to support the import of `node` modules into mock files, it cannot package mock files inline into client-side build code.
559
+ In some scenarios, it may be necessary to use the data provided by mock services for display purposes, but the project may have already been packaged, built and deployed without support from `vite` and this plugin's mock service. Since this plugin supports importing various `node` modules in mock files at the design stage, the mock file cannot be inline into client build code.
562
560
 
563
- To cater for such scenarios, the plugin provides support under `vite preview` as well as the ability to build a small, independently deployable mock service application at `vite build` that can be deployed to the relevant environment. The mock support is then implemented by proxy forwarding to the actual port by another http server such as `nginx`.
561
+ To meet such scenarios, on one hand, the plugin provides support under `vite preview`, and on the other hand, it also builds a small independent mock service application that can be deployed to relevant environments during `vite build`. This can then be forwarded through other HTTP servers like nginx to actual ports for mock support.
564
562
 
565
- Build the default output into the `dist/mockServer` directory and generate the following file:
563
+ The default output is built into the directory `dist/mockServer`, generating files as follows:
566
564
  ```sh
567
565
  ./mockServer
568
566
  ├── index.js
@@ -570,11 +568,11 @@ Build the default output into the `dist/mockServer` directory and generate the f
570
568
  └── package.json
571
569
  ```
572
570
 
573
- In this directory, after `npm install` to install the dependencies, `npm start` can be executed to start the mock server.
571
+ In this directory, execute `npm install` to install dependencies, and then execute `npm start` to start the mock server.
574
572
 
575
- default port: `8080`。
573
+ The default port is `8080`.
576
574
 
577
- Access the associated `mock` interface via `localhost:8080/`.
575
+ You can access related `mock` interfaces through `localhost:8080/`.
578
576
 
579
577
  ## Archives
580
578
 
package/README.zh-CN.md CHANGED
@@ -31,7 +31,7 @@
31
31
  - 🧲 非注入式,对客户端代码无侵入
32
32
  - 💡 ESModule/commonjs
33
33
  - 🦾 Typescript
34
- - 🏷 支持 json / json5 编写 mock 数据
34
+ - 🏷 支持 `json` / `json5` 编写 mock 数据
35
35
  - 📦 自动加载 mock 文件
36
36
  - 🎨 可选择你喜欢的任意用于生成mock数据库,如 `mockjs`,或者不使用其他库
37
37
  - 📥 路径规则匹配,请求参数匹配
@@ -161,11 +161,8 @@ export default defineConfig({
161
161
  ```ts
162
162
  [
163
163
  '**/node_modules/**',
164
- '**/test/**',
165
- 'src/**',
166
164
  '**/.vscode/**',
167
165
  '**/.git/**',
168
- '**/dist/**'
169
166
  ]
170
167
  ```
171
168
 
@@ -194,7 +191,7 @@ export default defineConfig({
194
191
 
195
192
  - `options.build`
196
193
 
197
- 构建可独立部署的小型mock服务时配置。
194
+ 需要构建可独立部署的小型mock服务时配置。
198
195
 
199
196
  **类型:** `boolean | ServerBuildOptions`
200
197
 
@@ -271,7 +268,7 @@ export default defineMock({
271
268
  */
272
269
  statusText: 'OK',
273
270
  /**
274
- * 请求验证器,通过验证器则返回 mock数据,否则不是用当前mock。
271
+ * 请求验证器,通过验证器则返回 mock数据,否则不使用当前mock。
275
272
  * 这对于一些场景中,某个接口需要通过不同的入参来返回不同的数据,
276
273
  * 验证器可以很好的解决这一类问题,将同个 url 分为多个 mock配置,
277
274
  * 根据 验证器来判断哪个mock配置生效。
@@ -292,9 +289,8 @@ export default defineMock({
292
289
  query: {},
293
290
  params: {},
294
291
  /**
295
- * refererQuery validates the query in the url of the page from which the request originated,
296
- * which makes it possible to modify parameters directly in the browser address bar to get
297
- * different mock data
292
+ * refererQuery 验证了请求来源页面 URL 中的查询参数,
293
+ * 这使得可以直接在浏览器地址栏中修改参数以获取不同的模拟数据。
298
294
  */
299
295
  refererQuery: {}
300
296
  },
@@ -571,7 +567,7 @@ export default defineMock({
571
567
  └── package.json
572
568
  ```
573
569
 
574
- 在该目录下,执行 `npm install` 安装依赖后,可执行 `npm start` 即可启动 mock server。
570
+ 在该目录下,执行 `npm install` 安装依赖后,执行 `npm start` 即可启动 mock server。
575
571
  默认端口为 `8080`。
576
572
  可通过 `localhost:8080/` 访问相关的 `mock` 接口。
577
573
 
package/dist/index.cjs CHANGED
@@ -38,7 +38,7 @@ __export(src_exports, {
38
38
  });
39
39
  module.exports = __toCommonJS(src_exports);
40
40
 
41
- // node_modules/.pnpm/tsup@6.6.3_typescript@4.9.5/node_modules/tsup/assets/cjs_shims.js
41
+ // node_modules/.pnpm/tsup@6.7.0_typescript@5.0.2/node_modules/tsup/assets/cjs_shims.js
42
42
  var getImportMetaUrl = () => typeof document === "undefined" ? new URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
43
43
  var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
44
44
 
@@ -53,7 +53,7 @@ var import_vite = require("vite");
53
53
 
54
54
  // package.json
55
55
  var name = "vite-plugin-mock-dev-server";
56
- var version = "1.0.5";
56
+ var version = "1.0.6";
57
57
 
58
58
  // src/esbuildPlugin.ts
59
59
  var import_promises = __toESM(require("fs/promises"), 1);
@@ -794,11 +794,8 @@ function mockDevServerPlugin({
794
794
  include = ["mock/**/*.mock.{js,ts,cjs,mjs,json,json5}"],
795
795
  exclude = [
796
796
  "**/node_modules/**",
797
- "**/test/**",
798
- "src/**",
799
797
  "**/.vscode/**",
800
- "**/.git/**",
801
- "**/dist/**"
798
+ "**/.git/**"
802
799
  ],
803
800
  reload = false,
804
801
  formidableOptions = {},
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import { createFilter, normalizePath } from "vite";
9
9
 
10
10
  // package.json
11
11
  var name = "vite-plugin-mock-dev-server";
12
- var version = "1.0.5";
12
+ var version = "1.0.6";
13
13
 
14
14
  // src/esbuildPlugin.ts
15
15
  import fsp from "fs/promises";
@@ -750,11 +750,8 @@ function mockDevServerPlugin({
750
750
  include = ["mock/**/*.mock.{js,ts,cjs,mjs,json,json5}"],
751
751
  exclude = [
752
752
  "**/node_modules/**",
753
- "**/test/**",
754
- "src/**",
755
753
  "**/.vscode/**",
756
- "**/.git/**",
757
- "**/dist/**"
754
+ "**/.git/**"
758
755
  ],
759
756
  reload = false,
760
757
  formidableOptions = {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-mock-dev-server",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "keywords": [
5
5
  "vite",
6
6
  "plugin",
@@ -33,7 +33,7 @@
33
33
  "chokidar": "^3.5.3",
34
34
  "co-body": "^6.1.0",
35
35
  "debug": "^4.3.4",
36
- "esbuild": "^0.17.11",
36
+ "esbuild": "^0.17.12",
37
37
  "fast-glob": "^3.2.12",
38
38
  "formidable": "^2.1.1",
39
39
  "http-status": "^1.6.2",
@@ -49,16 +49,16 @@
49
49
  "@types/debug": "^4.1.7",
50
50
  "@types/formidable": "^2.0.5",
51
51
  "@types/is-core-module": "^2.2.0",
52
- "@types/node": "^18.14.6",
52
+ "@types/node": "^18.15.5",
53
53
  "bumpp": "^9.0.0",
54
54
  "conventional-changelog-cli": "^2.2.2",
55
- "eslint": "^8.35.0",
55
+ "eslint": "^8.36.0",
56
56
  "mockjs": "^1.1.0",
57
- "prettier": "^2.8.4",
58
- "tsup": "^6.6.3",
59
- "typescript": "^4.9.5",
60
- "vite": "^4.1.4",
61
- "vitepress": "1.0.0-alpha.49",
57
+ "prettier": "^2.8.6",
58
+ "tsup": "^6.7.0",
59
+ "typescript": "^5.0.2",
60
+ "vite": "^4.2.1",
61
+ "vitepress": "1.0.0-alpha.61",
62
62
  "vue": "^3.2.47"
63
63
  },
64
64
  "peerDependencies": {