You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> The plugin no longer supports `CommonJS` imports. Please use `ESModule` to import the plugin.
57
+
58
+
----
59
+
60
+
> [!IMPORTANT]
61
+
> The current document is for the `v2` version of the plugin. If you are using the `v1` version, please refer to the [Migration Guide](https://vite-plugin-mock-dev-server.netlify.app/guide/migrate-v2).
62
+
55
63
## Install
56
64
57
65
```sh
@@ -100,7 +108,7 @@ By default, write mock data in the `mock` directory of your project's root direc
Retrieve the file path from the request through dynamic route matching using `:filepath(.*)`, obtain the file path from the request, return it as a file stream in the body, and set the correct `Content-Type` in the headers.
3
+
Retrieve the file path from the request through dynamic route matching using `*filepath`, obtain the file path from the request, return it as a file stream in the body, and set the correct `Content-Type` in the headers.
4
4
5
5
```ts
6
6
import { createReadStream } from'node:fs'
@@ -12,18 +12,18 @@ import { defineMock } from 'vite-plugin-mock-dev-server'
The plugin now automatically selects different compilers to process mock files based on different versions of Vite.
18
+
19
+
For the `vite@npm:rolldown-vite@latest` version, `rolldown` is used as the compiler.
20
+
21
+
## path-to-regexp Upgraded from v6 to v8
22
+
23
+
The plugin now uses [`path-to-regexp@v8`](https://github.com/pillarjs/path-to-regexp#readme) as the path matching engine.
24
+
25
+
Please refer to the [official documentation](https://github.com/pillarjs/path-to-regexp#unexpected--or-) for adaptation and upgrade.
26
+
27
+
## Plugin Configuration
28
+
29
+
Added a new `dir` configuration option to specify the directory for mock files, relative to `cwd`. The matching context for `include` and `exclude` is `cwd + dir`.
30
+
31
+
::: details Why was this adjustment made?
32
+
33
+
The plugin uses `chokidar` to monitor changes in mock files, starting the matching from the `cwd` directory by default. The search scope may be too large for medium to large projects,
34
+
35
+
which could lead to unnecessary performance overhead. Therefore, the `dir` configuration option has been added to further narrow down the search scope.
0 commit comments