vite-plugin-mock-data 6.0.0 → 6.0.1
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 +53 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,12 +15,58 @@ npm install vite-plugin-mock-data --save-dev
|
|
|
15
15
|
|
|
16
16
|
## Options
|
|
17
17
|
|
|
18
|
+
```ts
|
|
19
|
+
import { Config as SirvConfig, HTTPVersion, RouteOptions, Handler } from 'find-my-way';
|
|
20
|
+
|
|
21
|
+
export interface HandleRoute {
|
|
22
|
+
file?: string;
|
|
23
|
+
handler?: any | Handler<HTTPVersion.V1>;
|
|
24
|
+
options?: RouteOptions;
|
|
25
|
+
store?: any;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface RouteConfig {
|
|
29
|
+
[route: string]: string | Handler<HTTPVersion.V1> | HandleRoute;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface Options {
|
|
33
|
+
/**
|
|
34
|
+
* The directory to serve files from.
|
|
35
|
+
* @default `process.cwd()`
|
|
36
|
+
*/
|
|
37
|
+
cwd?: string;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* If `true`, these mock routes is matched after internal middlewares are installed.
|
|
41
|
+
* @default `false`
|
|
42
|
+
*/
|
|
43
|
+
isAfter?: boolean;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Specify the directory to define mock assets.
|
|
47
|
+
*/
|
|
48
|
+
assets?: string;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Initial options of `find-my-way`. see more at https://github.com/delvedor/find-my-way#findmywayoptions
|
|
52
|
+
*/
|
|
53
|
+
routerOptions?: SirvConfig<HTTPVersion.V1> | SirvConfig<HTTPVersion.V2>;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Initial list of mock routes that should be added to the dev server
|
|
57
|
+
* or specify the directory to define mock routes that should be added to the dev server.
|
|
58
|
+
*/
|
|
59
|
+
routes?: RouteConfig | Array<RouteConfig | string> | string;
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
18
63
|
* `cwd` - Default: `process.cwd()`.
|
|
19
64
|
* `isAfter` - If `true`, these mock routes is matched after internal middlewares are installed.
|
|
20
|
-
* `
|
|
21
|
-
* `
|
|
22
|
-
* `
|
|
23
|
-
* `
|
|
65
|
+
* `assets` - Specify the directory to define mock assets.
|
|
66
|
+
* `routerOptions` - [Initial options of `find-my-way`](https://github.com/delvedor/find-my-way#findmywayoptions)
|
|
67
|
+
* `routes`
|
|
68
|
+
* `RouteConfig | Array<RouteConfig | string>` - Initial list of mock routes that should be added to the dev server.
|
|
69
|
+
* `string` - Specify the directory to define mock routes that should be added to the dev server.
|
|
24
70
|
|
|
25
71
|
## Usage
|
|
26
72
|
|
|
@@ -33,7 +79,7 @@ import mockData from 'vite-plugin-mock-data';
|
|
|
33
79
|
export default defineConfig({
|
|
34
80
|
plugins: [
|
|
35
81
|
mockData({
|
|
36
|
-
|
|
82
|
+
assets: './mockAssets'
|
|
37
83
|
})
|
|
38
84
|
]
|
|
39
85
|
});
|
|
@@ -67,7 +113,7 @@ import mockData from 'vite-plugin-mock-data';
|
|
|
67
113
|
export default defineConfig({
|
|
68
114
|
plugins: [
|
|
69
115
|
mockData({
|
|
70
|
-
|
|
116
|
+
routes: {
|
|
71
117
|
'/hello': 'hello',
|
|
72
118
|
'/hello2'(req, res) {
|
|
73
119
|
res.statusCode = 200;
|
|
@@ -110,7 +156,7 @@ import mockData from 'vite-plugin-mock-data';
|
|
|
110
156
|
export default defineConfig({
|
|
111
157
|
plugins: [
|
|
112
158
|
mockData({
|
|
113
|
-
|
|
159
|
+
routes: './mock'
|
|
114
160
|
})
|
|
115
161
|
]
|
|
116
162
|
});
|