vite-plugin-mock-dev-server 0.3.16 → 0.3.18
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 +47 -1
- package/README.zh-CN.md +42 -1
- package/dist/index.cjs +473 -213
- package/dist/index.d.ts +68 -2
- package/dist/index.js +469 -210
- package/package.json +4 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Connect, Plugin } from 'vite';
|
|
2
2
|
import http from 'node:http';
|
|
3
3
|
import formidable from 'formidable';
|
|
4
|
+
import EventEmitter from 'node:events';
|
|
5
|
+
import chokidar from 'chokidar';
|
|
4
6
|
|
|
5
7
|
interface MockServerPluginOptions {
|
|
6
8
|
/**
|
|
@@ -19,6 +21,26 @@ interface MockServerPluginOptions {
|
|
|
19
21
|
* @see https://github.com/node-formidable/formidable#options
|
|
20
22
|
*/
|
|
21
23
|
formidableOptions?: formidable.Options;
|
|
24
|
+
/**
|
|
25
|
+
* 当需要构建一个小型mock服务时,可配置此项
|
|
26
|
+
*
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
build?: boolean | ServerBuildOption;
|
|
30
|
+
}
|
|
31
|
+
interface ServerBuildOption {
|
|
32
|
+
/**
|
|
33
|
+
* 服务启动端口
|
|
34
|
+
*
|
|
35
|
+
* @default 8080
|
|
36
|
+
*/
|
|
37
|
+
serverPort?: number;
|
|
38
|
+
/**
|
|
39
|
+
* 服务应用输出目录
|
|
40
|
+
*
|
|
41
|
+
* @default 'dist/mockServer'
|
|
42
|
+
*/
|
|
43
|
+
dist?: string;
|
|
22
44
|
}
|
|
23
45
|
type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'TRACE' | 'OPTIONS';
|
|
24
46
|
type ResponseBody = Record<string, any> | any[] | string | number | null;
|
|
@@ -116,7 +138,7 @@ interface MockOptionsItem {
|
|
|
116
138
|
type MockOptions = MockOptionsItem[];
|
|
117
139
|
type FormidableFile = formidable.File | formidable.File[];
|
|
118
140
|
|
|
119
|
-
declare function mockDevServerPlugin({ include, exclude, formidableOptions, }?: MockServerPluginOptions): Plugin;
|
|
141
|
+
declare function mockDevServerPlugin({ include, exclude, formidableOptions, build, }?: MockServerPluginOptions): Plugin[];
|
|
120
142
|
|
|
121
143
|
/**
|
|
122
144
|
* mock config helper
|
|
@@ -136,4 +158,48 @@ declare function mockDevServerPlugin({ include, exclude, formidableOptions, }?:
|
|
|
136
158
|
declare function defineMock(config: MockOptionsItem): MockOptionsItem;
|
|
137
159
|
declare function defineMock(config: MockOptions): MockOptions;
|
|
138
160
|
|
|
139
|
-
|
|
161
|
+
interface MockLoaderOptions {
|
|
162
|
+
cwd?: string;
|
|
163
|
+
include: string[];
|
|
164
|
+
exclude: string[];
|
|
165
|
+
define: Record<string, any>;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* mock配置加载器
|
|
169
|
+
*/
|
|
170
|
+
declare class MockLoader extends EventEmitter {
|
|
171
|
+
options: MockLoaderOptions;
|
|
172
|
+
static EXT_JSON: RegExp;
|
|
173
|
+
moduleCache: Map<string, MockOptions | MockOptionsItem>;
|
|
174
|
+
moduleDeps: Map<string, Set<string>>;
|
|
175
|
+
cwd: string;
|
|
176
|
+
mockWatcher: chokidar.FSWatcher;
|
|
177
|
+
depsWatcher: chokidar.FSWatcher;
|
|
178
|
+
moduleType: 'cjs' | 'esm';
|
|
179
|
+
private _mockData;
|
|
180
|
+
constructor(options: MockLoaderOptions);
|
|
181
|
+
get mockData(): Record<string, MockOptions>;
|
|
182
|
+
load(): Promise<void>;
|
|
183
|
+
private watchMockEntry;
|
|
184
|
+
/**
|
|
185
|
+
* 监听 mock文件依赖的本地文件变动,
|
|
186
|
+
* mock依赖文件更新,mock文件也一并更新
|
|
187
|
+
*/
|
|
188
|
+
private watchDeps;
|
|
189
|
+
close(): void;
|
|
190
|
+
private updateMockList;
|
|
191
|
+
private updateModuleDeps;
|
|
192
|
+
private loadMock;
|
|
193
|
+
private loadJson;
|
|
194
|
+
private loadModule;
|
|
195
|
+
private loadFromCode;
|
|
196
|
+
private transformWithEsbuild;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
interface BaseMiddlewareOptions {
|
|
200
|
+
formidableOptions: MockServerPluginOptions['formidableOptions'];
|
|
201
|
+
proxies: string[];
|
|
202
|
+
}
|
|
203
|
+
declare function baseMiddleware(mockData: MockLoader['mockData'], { formidableOptions, proxies }: BaseMiddlewareOptions): Connect.NextHandleFunction;
|
|
204
|
+
|
|
205
|
+
export { BaseMiddlewareOptions, FormidableFile, MockOptions, MockOptionsItem, MockServerPluginOptions, baseMiddleware, mockDevServerPlugin as default, defineMock, mockDevServerPlugin };
|