vite-plugin-mock-dev-server 0.3.5 → 0.3.7

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
@@ -8,7 +8,7 @@
8
8
  <p align="center">
9
9
  <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>
10
10
  <img alt="node-current" src="https://img.shields.io/node/v/vite-plugin-mock-dev-server?style=flat-square">
11
- <img alt="GitHub package.json dependency version (prod)" src="https://img.shields.io/github/package-json/dependency-version/pengzhanbo/vite-plugin-mock-dev-server/vite?style=flat-square">
11
+ <img alt="npm peer dependency version" src="https://img.shields.io/npm/dependency-version/vite-plugin-mock-dev-server/peer/vite?style=flat-square">
12
12
  <img alt="GitHub" src="https://img.shields.io/github/license/pengzhanbo/vite-plugin-mock-dev-server?style=flat-square">
13
13
  </p>
14
14
  <br>
@@ -34,6 +34,10 @@
34
34
  - ⚖️ Use `server.proxy`
35
35
  - 🍕 Support `viteConfig.define` in mock file
36
36
 
37
+ ## Documentation
38
+
39
+ See the [documentation](https://vite-plugin-mock-dev-server.netlify.app/) to learn more.
40
+ [![Netlify Status](https://api.netlify.com/api/v1/badges/9ccda610-2c6a-4cd0-aeaa-a8932f2b477c/deploy-status)](https://app.netlify.com/sites/vite-plugin-mock-dev-server/deploys)
37
41
 
38
42
  ## Usage
39
43
 
@@ -411,3 +415,11 @@ Use json / json5
411
415
  }
412
416
  }
413
417
  ```
418
+
419
+ ## Archives
420
+
421
+ [awesome-vite](https://github.com/vitejs/awesome-vite#helpers)
422
+
423
+ ## LICENSE
424
+
425
+ [GPL-3.0](/LICENSE)
package/README.zh-CN.md CHANGED
@@ -10,7 +10,7 @@
10
10
  <p align="center">
11
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
12
  <img alt="node-current" src="https://img.shields.io/node/v/vite-plugin-mock-dev-server?style=flat-square">
13
- <img alt="GitHub package.json dependency version (prod)" src="https://img.shields.io/github/package-json/dependency-version/pengzhanbo/vite-plugin-mock-dev-server/vite?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
14
  <img alt="GitHub" src="https://img.shields.io/github/license/pengzhanbo/vite-plugin-mock-dev-server?style=flat-square">
15
15
  </p>
16
16
  <br>
@@ -36,6 +36,10 @@
36
36
  - 🍕 支持在 mock文件中使用 `viteConfig.define`配置字段
37
37
 
38
38
 
39
+ ## 文档
40
+
41
+ 查看 [Documentation](https://vite-plugin-mock-dev-server.netlify.app/) 了解更多。
42
+ [![Netlify Status](https://api.netlify.com/api/v1/badges/9ccda610-2c6a-4cd0-aeaa-a8932f2b477c/deploy-status)](https://app.netlify.com/sites/vite-plugin-mock-dev-server/deploys)
39
43
  ## 使用
40
44
 
41
45
  ### 安装
@@ -403,3 +407,11 @@ export default defineMock({
403
407
  }
404
408
  }
405
409
  ```
410
+
411
+ ## Archives
412
+
413
+ [awesome-vite](https://github.com/vitejs/awesome-vite#helpers)
414
+
415
+ ## LICENSE
416
+
417
+ [GPL-3.0](/LICENSE)
package/dist/index.cjs CHANGED
@@ -274,6 +274,11 @@ var _MockLoader = class extends import_node_events.default {
274
274
  }
275
275
  async transformWithEsbuild(filepath, isESM) {
276
276
  var _a;
277
+ const userDefine = {};
278
+ for (const key in this.options.define) {
279
+ const val = this.options.define[key];
280
+ userDefine[key] = typeof val === "string" ? val : JSON.stringify(val);
281
+ }
277
282
  try {
278
283
  const result = await (0, import_esbuild.build)({
279
284
  entryPoints: [filepath],
@@ -284,7 +289,7 @@ var _MockLoader = class extends import_node_events.default {
284
289
  bundle: true,
285
290
  metafile: true,
286
291
  format: isESM ? "esm" : "cjs",
287
- define: this.options.define,
292
+ define: userDefine,
288
293
  plugins: [
289
294
  {
290
295
  name: "externalize-deps",
package/dist/index.d.ts CHANGED
@@ -14,8 +14,8 @@ interface MockServerPluginOptions {
14
14
  */
15
15
  exclude?: string | string[];
16
16
  }
17
- declare type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'TRACE' | 'OPTIONS';
18
- declare type ResponseBody = Record<string, any> | any[] | string | number | null;
17
+ type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'TRACE' | 'OPTIONS';
18
+ type ResponseBody = Record<string, any> | any[] | string | number | null;
19
19
  interface ResponseReq {
20
20
  /**
21
21
  * 请求地址中位于 `?` 后面的 queryString,已解析为 json
@@ -40,7 +40,7 @@ interface ResponseBodyFn {
40
40
  interface ResponseHeaderFn {
41
41
  (request: ResponseReq): Headers | Promise<Headers>;
42
42
  }
43
- declare type Headers = Record<string, any>;
43
+ type Headers = Record<string, any>;
44
44
  interface MockOptionsItem {
45
45
  /**
46
46
  * 需要做mock的接口地址,
@@ -107,7 +107,7 @@ interface MockOptionsItem {
107
107
  */
108
108
  validator?: Partial<ResponseReq> | ((request: ResponseReq) => boolean);
109
109
  }
110
- declare type MockOptions = MockOptionsItem[];
110
+ type MockOptions = MockOptionsItem[];
111
111
 
112
112
  declare function mockDevServerPlugin({ include, exclude, }?: MockServerPluginOptions): Plugin;
113
113
 
package/dist/index.js CHANGED
@@ -239,6 +239,11 @@ var _MockLoader = class extends EventEmitter {
239
239
  }
240
240
  async transformWithEsbuild(filepath, isESM) {
241
241
  var _a;
242
+ const userDefine = {};
243
+ for (const key in this.options.define) {
244
+ const val = this.options.define[key];
245
+ userDefine[key] = typeof val === "string" ? val : JSON.stringify(val);
246
+ }
242
247
  try {
243
248
  const result = await build({
244
249
  entryPoints: [filepath],
@@ -249,7 +254,7 @@ var _MockLoader = class extends EventEmitter {
249
254
  bundle: true,
250
255
  metafile: true,
251
256
  format: isESM ? "esm" : "cjs",
252
- define: this.options.define,
257
+ define: userDefine,
253
258
  plugins: [
254
259
  {
255
260
  name: "externalize-deps",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-mock-dev-server",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "keywords": [
5
5
  "vite",
6
6
  "plugin",
@@ -12,6 +12,7 @@
12
12
  "type": "git",
13
13
  "url": "https://github.com/pengzhanbo/vite-plugin-mock-dev-server"
14
14
  },
15
+ "homepage": "https://vite-plugin-mock-dev-server.netlify.app",
15
16
  "author": "pengzhanbo <q942450674@outlook.com> (https://github.com/pengzhanbo)",
16
17
  "license": "GPL-3.0",
17
18
  "type": "module",
@@ -46,11 +47,10 @@
46
47
  "chokidar": "^3.5.3",
47
48
  "co-body": "^6.1.0",
48
49
  "debug": "^4.3.4",
49
- "esbuild": "^0.15.12",
50
+ "esbuild": "^0.16.9",
50
51
  "fast-glob": "^3.2.12",
51
- "json5": "^2.2.1",
52
- "path-to-regexp": "^6.2.1",
53
- "vite": "^3.2.0"
52
+ "json5": "^2.2.2",
53
+ "path-to-regexp": "^6.2.1"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@pengzhanbo/eslint-config-ts": "^0.2.10",
@@ -59,23 +59,29 @@
59
59
  "@types/debug": "^4.1.7",
60
60
  "@types/node": "^18.11.7",
61
61
  "bumpp": "^8.2.1",
62
- "eslint": "^8.26.0",
62
+ "eslint": "^8.30.0",
63
63
  "mockjs": "^1.1.0",
64
- "prettier": "^2.7.1",
65
- "tsup": "^6.3.0",
66
- "typescript": "^4.8.4",
67
- "vite-plugin-mock-dev-server": "file:"
64
+ "prettier": "^2.8.1",
65
+ "tsup": "^6.5.0",
66
+ "typescript": "^4.9.4",
67
+ "vite": "^4.0.2",
68
+ "vite-plugin-mock-dev-server": "file:",
69
+ "vitepress": "1.0.0-alpha.32",
70
+ "vue": "^3.2.45"
68
71
  },
69
72
  "peerDependencies": {
70
73
  "vite": ">=3.0.0"
71
74
  },
72
- "packageManager": "pnpm@7.14.0",
75
+ "packageManager": "pnpm@7.18.2",
73
76
  "engines": {
74
- "node": ">=16"
77
+ "node": "^14.18.0 || >=16"
75
78
  },
76
79
  "scripts": {
77
80
  "dev": "DEBUG=vite:plugin-mock-dev-server vite example --config ./example/vite.config.ts",
78
81
  "build": "tsup",
82
+ "docs:dev": "vitepress dev docs",
83
+ "docs:build": "vitepress build docs",
84
+ "docs:preview": "vitepress preview docs",
79
85
  "release": "bumpp package.json --commit --push --tag && pnpm publish --access public"
80
86
  }
81
87
  }