vite-plugin-mock-dev-server 0.3.16 → 0.3.17

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
@@ -37,7 +37,10 @@
37
37
  - ⚖️ Use `server.proxy`
38
38
  - 🍕 Support `viteConfig.define` in mock file
39
39
  - 📤 Support `multipart` content-type,mock upload file.
40
- - 🌈 Support `vite preview` mode.
40
+ - 🌈 Support `vite preview` mode
41
+ - 🗂 Support for building small mock services that can be deployed independently
42
+
43
+
41
44
  ## Documentation
42
45
 
43
46
  See the [documentation](https://vite-plugin-mock-dev-server.netlify.app/) to learn more.
@@ -163,6 +166,29 @@ export default defineConfig({
163
166
  })
164
167
  ```
165
168
 
169
+ - `options.build`
170
+
171
+ When building a small, independently deployable mock service.
172
+
173
+ Type: `boolean | ServerBuildOptions`
174
+
175
+ Default:`false`
176
+
177
+ ```ts
178
+ interface ServerBuildOptions {
179
+ /**
180
+ * server port
181
+ * @default 8080
182
+ */
183
+ serverPort?: number
184
+ /**
185
+ * build output dir
186
+ @default 'mockServer'
187
+ */
188
+ dist?: string
189
+ }
190
+ ```
191
+
166
192
  ### defineMock(config)
167
193
 
168
194
  Mock Type Helper
@@ -474,6 +500,26 @@ export default defineMock({
474
500
  })
475
501
  ```
476
502
 
503
+ ## Mock Services
504
+
505
+ In some scenarios, you may need to use the data support provided by the mock service for display purposes, but it is possible that the project has been packaged and deployed as a build and is out of the mock service support provided by `vite` and this plugin. Since this plugin was designed to support the import of `node` modules into mock files, it cannot package mock files inline into client-side build code.
506
+
507
+ To cater for such scenarios, the plugin provides support under `vite preview` as well as the ability to build a small, independently deployable mock service application at `vite build` that can be deployed to the relevant environment. The mock support is then implemented by proxy forwarding to the actual port by another http server such as `nginx`.
508
+
509
+ Build the default output into the `dist/mockServer` directory and generate the following file:
510
+ ```sh
511
+ ./mockServer
512
+ ├── index.js
513
+ ├── mock-data.js
514
+ └── package.json
515
+ ```
516
+
517
+ In this directory, after `npm install` to install the dependencies, `npm start` can be executed to start the mock server.
518
+
519
+ default port: `8080`。
520
+
521
+ Access the associated `mock` interface via `localhost:8080/`.
522
+
477
523
  ## Archives
478
524
 
479
525
  [awesome-vite](https://github.com/vitejs/awesome-vite#helpers)
package/README.zh-CN.md CHANGED
@@ -38,7 +38,8 @@
38
38
  - ⚖️ 使用 `server.proxy` 配置
39
39
  - 🍕 支持在 mock文件中使用 `viteConfig.define`配置字段
40
40
  - 📤 支持 multipart 类型,模拟文件上传
41
- - 🌈 支持 `vite preview` 模式.
41
+ - 🌈 支持 `vite preview` 模式
42
+ - 🗂 支持构建可独立部署的小型mock服务
42
43
 
43
44
 
44
45
  ## 文档
@@ -166,6 +167,28 @@ export default defineConfig({
166
167
  })
167
168
  ```
168
169
 
170
+ - `options.build`
171
+
172
+ 构建可独立部署的小型mock服务时配置。
173
+
174
+ 类型: `boolean | ServerBuildOptions`
175
+
176
+ 默认值:`false`
177
+
178
+ ```ts
179
+ interface ServerBuildOptions {
180
+ /**
181
+ * 服务端口
182
+ * @default 8080
183
+ */
184
+ serverPort?: number
185
+ /**
186
+ * 构建输出目录
187
+ @default 'mockServer'
188
+ */
189
+ dist?: string
190
+ }
191
+ ```
169
192
 
170
193
  ### defineMock(config)
171
194
 
@@ -479,6 +502,24 @@ export default defineMock({
479
502
  })
480
503
  ```
481
504
 
505
+ ## 独立部署的小型mock服务
506
+
507
+ 在一些场景中,可能会需要使用mock服务提供的数据支持,用于展示,但可能项目已完成打包构建部署,已脱离 `vite` 和本插件提供的 mock服务支持。由于本插件在设计之初,支持在mock文件中引入各种 `node` 模块,所以不能将 mock文件打包内联到客户端构建代码中。
508
+
509
+ 为了能够满足这类场景,插件一方面提供了 `vite preview` 下的支持,同时还提供了在 `vite build` 时,也构建一个可独立部署的 小型mock服务应用,可以将这个应用部署到相关的环境,后通过其他http服务器如nginx做代理转发到实际端口实现mock支持。
510
+
511
+ 构建默认输出到 `dist/mockServer` 目录中,并生成如下文件:
512
+ ```sh
513
+ ./mockServer
514
+ ├── index.js
515
+ ├── mock-data.js
516
+ └── package.json
517
+ ```
518
+
519
+ 在该目录下,执行 `npm install` 安装依赖后,可执行 `npm start` 即可启动 mock server。
520
+ 默认端口为 `8080`。
521
+ 可通过 `localhost:8080/` 访问相关的 `mock` 接口。
522
+
482
523
  ## Archives
483
524
 
484
525
  [awesome-vite](https://github.com/vitejs/awesome-vite#helpers)