vite-plugin-slow-response
v1.0.6
Published
A Vite plugin that simulates slow responses from the dev server.
Maintainers
Readme
Vite Plugin Slow Response
A Vite plugin that simulates slow responses from the dev server.
Installation
npm install vite-plugin-slow-response --save-devUsage
[!NOTE] The plugin only affects requests to the Vite dev server. It does not affect production builds.
Add the following to your vite.config.ts file.
import { defineConfig } from 'vite'
import slowResponse from 'vite-plugin-slow-response'
export default defineConfig({
plugins: [
slowResponse('/api', 2000)
],
})Any request to /api will be delayed by 2000 milliseconds.
[!TIP] This will work with Vite dev server proxies.
Multiple paths can be specified by calling the plugin multiple times.
export default defineConfig({
plugins: [
slowResponse('/api', 2000),
slowResponse('/auth/login', 1000)
],
})To simulate slow responses for all requests:
export default defineConfig({
plugins: [
slowResponse('/', 2000)
],
})Disable the plugin by setting the delay to 0. This completely bypasses the middleware creation, so there is no performance overhead:
export default defineConfig({
plugins: [
slowResponse('/', 0)
],
})Options
| Option | Type | Default | Description |
| ------- | -------- | ------- | ------------------------------------------------------ |
| path | string | | The path to match for slow responses. |
| delay | number | 0 | The delay in milliseconds before the response is sent. |
