vite-plugin-mock-dev-server 0.3.14 → 0.3.15
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 +6 -4
- package/README.zh-CN.md +5 -2
- package/dist/index.cjs +12 -10
- package/dist/index.js +11 -9
- package/package.json +37 -36
package/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
<br>
|
|
4
4
|
<br>
|
|
5
|
-
<p align="center">
|
|
5
|
+
<p align="center">
|
|
6
|
+
<b>Vite Plugin for API mock dev server.</b>
|
|
7
|
+
</p>
|
|
6
8
|
|
|
7
9
|
<br>
|
|
8
10
|
<p align="center">
|
|
@@ -10,6 +12,7 @@
|
|
|
10
12
|
<img alt="node-current" src="https://img.shields.io/node/v/vite-plugin-mock-dev-server?style=flat-square">
|
|
11
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">
|
|
12
14
|
<img alt="GitHub" src="https://img.shields.io/github/license/pengzhanbo/vite-plugin-mock-dev-server?style=flat-square">
|
|
15
|
+
<img alt="npm" src="https://img.shields.io/npm/dm/vite-plugin-mock-dev-server?style=flat-square">
|
|
13
16
|
</p>
|
|
14
17
|
<br>
|
|
15
18
|
<p align="center">
|
|
@@ -125,14 +128,13 @@ export default defineConfig({
|
|
|
125
128
|
|
|
126
129
|
- `options.exclude`
|
|
127
130
|
|
|
128
|
-
When you configure the mock files to be read, the files you want to exclude can be a directory,
|
|
131
|
+
When you configure the mock files to be read, the files you want to exclude can be a directory, glob, or array
|
|
129
132
|
|
|
130
133
|
Default:
|
|
131
134
|
```ts
|
|
132
135
|
[
|
|
133
136
|
'**/node_modules/**',
|
|
134
137
|
'**/test/**',
|
|
135
|
-
'**/cypress/**',
|
|
136
138
|
'src/**',
|
|
137
139
|
'**/.vscode/**',
|
|
138
140
|
'**/.git/**',
|
|
@@ -293,7 +295,7 @@ export default defineMock({
|
|
|
293
295
|
```
|
|
294
296
|
|
|
295
297
|
#### Example 2:
|
|
296
|
-
Match `/api/test` ,And returns a
|
|
298
|
+
Match `/api/test` ,And returns a static content data
|
|
297
299
|
```ts
|
|
298
300
|
export default defineMock({
|
|
299
301
|
url: '/api/test',
|
package/README.zh-CN.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
<br>
|
|
4
4
|
<br>
|
|
5
|
-
<p align="center">
|
|
5
|
+
<p align="center">
|
|
6
|
+
<b>vite mock开发服务(mock-dev-server)插件。</b>
|
|
7
|
+
</p>
|
|
6
8
|
|
|
7
9
|
<p align="center">在 vite 开发环境中,注入一个 mock-dev-server。</p>
|
|
8
10
|
|
|
@@ -12,6 +14,7 @@
|
|
|
12
14
|
<img alt="node-current" src="https://img.shields.io/node/v/vite-plugin-mock-dev-server?style=flat-square">
|
|
13
15
|
<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
16
|
<img alt="GitHub" src="https://img.shields.io/github/license/pengzhanbo/vite-plugin-mock-dev-server?style=flat-square">
|
|
17
|
+
<img alt="npm" src="https://img.shields.io/npm/dm/vite-plugin-mock-dev-server?style=flat-square">
|
|
15
18
|
</p>
|
|
16
19
|
<br>
|
|
17
20
|
<p align="center">
|
|
@@ -28,7 +31,7 @@
|
|
|
28
31
|
- 🦾 Typescript
|
|
29
32
|
- 🏷 支持 json / json5 编写 mock 数据
|
|
30
33
|
- 📦 自动加载 mock 文件
|
|
31
|
-
- 🎨 可选择你喜欢的任意用于生成mock数据库,如 `mockjs
|
|
34
|
+
- 🎨 可选择你喜欢的任意用于生成mock数据库,如 `mockjs`,或者不使用其他库
|
|
32
35
|
- 📥 路径规则匹配,请求参数匹配
|
|
33
36
|
- ⚙️ 随意开启或关闭对某个接口的 mock配置
|
|
34
37
|
- 🔥 热更新
|
package/dist/index.cjs
CHANGED
|
@@ -42,11 +42,11 @@ var import_node_fs2 = __toESM(require("fs"), 1);
|
|
|
42
42
|
var import_node_module = require("module");
|
|
43
43
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
44
44
|
var import_node_url2 = require("url");
|
|
45
|
-
var import_pluginutils = require("@rollup/pluginutils");
|
|
46
45
|
var import_chokidar = __toESM(require("chokidar"), 1);
|
|
47
46
|
var import_esbuild = require("esbuild");
|
|
48
47
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
49
48
|
var import_json5 = __toESM(require("json5"), 1);
|
|
49
|
+
var import_vite = require("vite");
|
|
50
50
|
|
|
51
51
|
// src/utils.ts
|
|
52
52
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
@@ -85,11 +85,11 @@ var _require = (0, import_node_module.createRequire)(_dirname);
|
|
|
85
85
|
var _MockLoader = class extends import_node_events.default {
|
|
86
86
|
constructor(options) {
|
|
87
87
|
super();
|
|
88
|
+
this.options = options;
|
|
88
89
|
this.moduleCache = /* @__PURE__ */ new Map();
|
|
89
90
|
this.moduleDeps = /* @__PURE__ */ new Map();
|
|
90
91
|
this._mockList = [];
|
|
91
92
|
this.moduleType = "cjs";
|
|
92
|
-
this.options = options;
|
|
93
93
|
this.cwd = options.cwd || process.cwd();
|
|
94
94
|
try {
|
|
95
95
|
const pkg = lookupFile(this.cwd, ["package.json"]);
|
|
@@ -105,7 +105,7 @@ var _MockLoader = class extends import_node_events.default {
|
|
|
105
105
|
const includePaths = await (0, import_fast_glob.default)(include, {
|
|
106
106
|
cwd: this.cwd
|
|
107
107
|
});
|
|
108
|
-
const includeFilter = (0,
|
|
108
|
+
const includeFilter = (0, import_vite.createFilter)(include, exclude, {
|
|
109
109
|
resolve: false
|
|
110
110
|
});
|
|
111
111
|
this.watchMockEntry();
|
|
@@ -274,11 +274,6 @@ 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
|
-
}
|
|
282
277
|
try {
|
|
283
278
|
const result = await (0, import_esbuild.build)({
|
|
284
279
|
entryPoints: [filepath],
|
|
@@ -289,7 +284,7 @@ var _MockLoader = class extends import_node_events.default {
|
|
|
289
284
|
bundle: true,
|
|
290
285
|
metafile: true,
|
|
291
286
|
format: isESM ? "esm" : "cjs",
|
|
292
|
-
define:
|
|
287
|
+
define: this.options.define,
|
|
293
288
|
plugins: [
|
|
294
289
|
{
|
|
295
290
|
name: "externalize-deps",
|
|
@@ -377,10 +372,17 @@ function equalObj(left, right) {
|
|
|
377
372
|
async function mockServerMiddleware(httpServer, config, options) {
|
|
378
373
|
const include = isArray(options.include) ? options.include : [options.include];
|
|
379
374
|
const exclude = isArray(options.exclude) ? options.exclude : [options.exclude];
|
|
375
|
+
const define = {};
|
|
376
|
+
if (config.define) {
|
|
377
|
+
for (const key in config.define) {
|
|
378
|
+
const val = config.define[key];
|
|
379
|
+
define[key] = typeof val === "string" ? val : JSON.stringify(val);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
380
382
|
const loader = new MockLoader({
|
|
381
383
|
include,
|
|
382
384
|
exclude,
|
|
383
|
-
define
|
|
385
|
+
define
|
|
384
386
|
});
|
|
385
387
|
await loader.load();
|
|
386
388
|
httpServer == null ? void 0 : httpServer.on("close", () => loader.close());
|
package/dist/index.js
CHANGED
|
@@ -8,11 +8,11 @@ import fs2 from "fs";
|
|
|
8
8
|
import { createRequire } from "module";
|
|
9
9
|
import path2 from "path";
|
|
10
10
|
import { pathToFileURL } from "url";
|
|
11
|
-
import { createFilter } from "@rollup/pluginutils";
|
|
12
11
|
import chokidar from "chokidar";
|
|
13
12
|
import { build } from "esbuild";
|
|
14
13
|
import fastGlob from "fast-glob";
|
|
15
14
|
import JSON5 from "json5";
|
|
15
|
+
import { createFilter } from "vite";
|
|
16
16
|
|
|
17
17
|
// src/utils.ts
|
|
18
18
|
import fs from "fs";
|
|
@@ -50,11 +50,11 @@ var _require = createRequire(_dirname);
|
|
|
50
50
|
var _MockLoader = class extends EventEmitter {
|
|
51
51
|
constructor(options) {
|
|
52
52
|
super();
|
|
53
|
+
this.options = options;
|
|
53
54
|
this.moduleCache = /* @__PURE__ */ new Map();
|
|
54
55
|
this.moduleDeps = /* @__PURE__ */ new Map();
|
|
55
56
|
this._mockList = [];
|
|
56
57
|
this.moduleType = "cjs";
|
|
57
|
-
this.options = options;
|
|
58
58
|
this.cwd = options.cwd || process.cwd();
|
|
59
59
|
try {
|
|
60
60
|
const pkg = lookupFile(this.cwd, ["package.json"]);
|
|
@@ -239,11 +239,6 @@ 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
|
-
}
|
|
247
242
|
try {
|
|
248
243
|
const result = await build({
|
|
249
244
|
entryPoints: [filepath],
|
|
@@ -254,7 +249,7 @@ var _MockLoader = class extends EventEmitter {
|
|
|
254
249
|
bundle: true,
|
|
255
250
|
metafile: true,
|
|
256
251
|
format: isESM ? "esm" : "cjs",
|
|
257
|
-
define:
|
|
252
|
+
define: this.options.define,
|
|
258
253
|
plugins: [
|
|
259
254
|
{
|
|
260
255
|
name: "externalize-deps",
|
|
@@ -342,10 +337,17 @@ function equalObj(left, right) {
|
|
|
342
337
|
async function mockServerMiddleware(httpServer, config, options) {
|
|
343
338
|
const include = isArray(options.include) ? options.include : [options.include];
|
|
344
339
|
const exclude = isArray(options.exclude) ? options.exclude : [options.exclude];
|
|
340
|
+
const define = {};
|
|
341
|
+
if (config.define) {
|
|
342
|
+
for (const key in config.define) {
|
|
343
|
+
const val = config.define[key];
|
|
344
|
+
define[key] = typeof val === "string" ? val : JSON.stringify(val);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
345
347
|
const loader = new MockLoader({
|
|
346
348
|
include,
|
|
347
349
|
exclude,
|
|
348
|
-
define
|
|
350
|
+
define
|
|
349
351
|
});
|
|
350
352
|
await loader.load();
|
|
351
353
|
httpServer == null ? void 0 : httpServer.on("close", () => loader.close());
|
package/package.json
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-mock-dev-server",
|
|
3
|
-
"
|
|
4
|
-
"version": "0.3.14",
|
|
5
|
-
"packageManager": "pnpm@7.18.2",
|
|
6
|
-
"author": "pengzhanbo <q942450674@outlook.com> (https://github.com/pengzhanbo)",
|
|
7
|
-
"license": "GPL-3.0",
|
|
8
|
-
"homepage": "https://vite-plugin-mock-dev-server.netlify.app",
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "https://github.com/pengzhanbo/vite-plugin-mock-dev-server"
|
|
12
|
-
},
|
|
3
|
+
"version": "0.3.15",
|
|
13
4
|
"keywords": [
|
|
14
5
|
"vite",
|
|
15
6
|
"plugin",
|
|
@@ -17,6 +8,14 @@
|
|
|
17
8
|
"mock",
|
|
18
9
|
"mock-server"
|
|
19
10
|
],
|
|
11
|
+
"homepage": "https://vite-plugin-mock-dev-server.netlify.app",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/pengzhanbo/vite-plugin-mock-dev-server"
|
|
15
|
+
},
|
|
16
|
+
"license": "GPL-3.0",
|
|
17
|
+
"author": "pengzhanbo <q942450674@outlook.com> (https://github.com/pengzhanbo)",
|
|
18
|
+
"type": "module",
|
|
20
19
|
"exports": {
|
|
21
20
|
".": {
|
|
22
21
|
"require": "./dist/index.cjs",
|
|
@@ -29,28 +28,8 @@
|
|
|
29
28
|
"files": [
|
|
30
29
|
"dist"
|
|
31
30
|
],
|
|
32
|
-
"engines": {
|
|
33
|
-
"node": "^14.18.0 || >=16"
|
|
34
|
-
},
|
|
35
|
-
"tsup": {
|
|
36
|
-
"entry": [
|
|
37
|
-
"src/index.ts"
|
|
38
|
-
],
|
|
39
|
-
"sourcemap": false,
|
|
40
|
-
"dts": true,
|
|
41
|
-
"splitting": false,
|
|
42
|
-
"clean": true,
|
|
43
|
-
"format": [
|
|
44
|
-
"esm",
|
|
45
|
-
"cjs"
|
|
46
|
-
]
|
|
47
|
-
},
|
|
48
31
|
"prettier": "@pengzhanbo/prettier-config",
|
|
49
|
-
"peerDependencies": {
|
|
50
|
-
"vite": ">=3.0.0"
|
|
51
|
-
},
|
|
52
32
|
"dependencies": {
|
|
53
|
-
"@rollup/pluginutils": "^5.0.2",
|
|
54
33
|
"chokidar": "^3.5.3",
|
|
55
34
|
"co-body": "^6.1.0",
|
|
56
35
|
"debug": "^4.3.4",
|
|
@@ -61,13 +40,14 @@
|
|
|
61
40
|
"path-to-regexp": "^6.2.1"
|
|
62
41
|
},
|
|
63
42
|
"devDependencies": {
|
|
64
|
-
"@pengzhanbo/eslint-config-ts": "^0.3.
|
|
65
|
-
"@pengzhanbo/prettier-config": "^0.3.
|
|
43
|
+
"@pengzhanbo/eslint-config-ts": "^0.3.2",
|
|
44
|
+
"@pengzhanbo/prettier-config": "^0.3.2",
|
|
66
45
|
"@types/co-body": "^6.1.0",
|
|
67
46
|
"@types/debug": "^4.1.7",
|
|
68
47
|
"@types/formidable": "^2.0.5",
|
|
69
48
|
"@types/node": "^18.11.7",
|
|
70
49
|
"bumpp": "^8.2.1",
|
|
50
|
+
"conventional-changelog-cli": "^2.2.2",
|
|
71
51
|
"eslint": "^8.31.0",
|
|
72
52
|
"mockjs": "^1.1.0",
|
|
73
53
|
"prettier": "^2.8.1",
|
|
@@ -75,16 +55,37 @@
|
|
|
75
55
|
"typescript": "^4.9.4",
|
|
76
56
|
"vite": "^4.0.2",
|
|
77
57
|
"vite-plugin-mock-dev-server": "file:",
|
|
78
|
-
"vitepress": "1.0.0-alpha.
|
|
58
|
+
"vitepress": "1.0.0-alpha.35",
|
|
79
59
|
"vue": "^3.2.45"
|
|
80
60
|
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"vite": ">=3.0.0"
|
|
63
|
+
},
|
|
64
|
+
"packageManager": "pnpm@7.18.2",
|
|
65
|
+
"engines": {
|
|
66
|
+
"node": "^14.18.0 || >=16"
|
|
67
|
+
},
|
|
68
|
+
"tsup": {
|
|
69
|
+
"entry": [
|
|
70
|
+
"src/index.ts"
|
|
71
|
+
],
|
|
72
|
+
"sourcemap": false,
|
|
73
|
+
"dts": true,
|
|
74
|
+
"splitting": false,
|
|
75
|
+
"clean": true,
|
|
76
|
+
"format": [
|
|
77
|
+
"esm",
|
|
78
|
+
"cjs"
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
81
|
"scripts": {
|
|
82
|
-
"dev": "DEBUG=vite:plugin-mock-dev-server vite example --config ./example/vite.config.ts",
|
|
83
82
|
"build": "tsup",
|
|
84
|
-
"
|
|
83
|
+
"dev": "DEBUG=vite:plugin-mock-dev-server vite example --config ./example/vite.config.ts",
|
|
85
84
|
"docs:build": "vitepress build docs",
|
|
85
|
+
"docs:dev": "vitepress dev docs",
|
|
86
86
|
"docs:preview": "vitepress preview docs",
|
|
87
87
|
"lint": "eslint .",
|
|
88
|
-
"release": "
|
|
88
|
+
"release:changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
|
|
89
|
+
"release": "bumpp package.json --execute=\"pnpm release:changelog\" --commit --all --push --tag && pnpm publish --access public"
|
|
89
90
|
}
|
|
90
91
|
}
|