-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
232 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# @admin-pkg/vite-plugin-msw | ||
|
||
Mock Service Worker browser and node integration for Vite. | ||
|
||
## Usage | ||
|
||
### Install | ||
|
||
```sh | ||
npm install --save-dev @admin-pkg/vite-plugin-msw | ||
# yarn add --dev @admin-pkg/vite-plugin-msw | ||
# pnpm add --save-dev @admin-pkg/vite-plugin-msw | ||
``` | ||
|
||
### Define mocks | ||
|
||
https://mswjs.io/docs/getting-started/mocks | ||
|
||
### Add to Vite config | ||
|
||
```ts | ||
// Import plugin | ||
import msw from '@admin-pkg/vite-plugin-msw'; | ||
|
||
// Import msw handlers | ||
import { handlers } from '../mocks/handlers'; | ||
|
||
// Pass them to plugin | ||
export default defineConfig({ | ||
plugins: [msw({ handlers })], | ||
}); | ||
``` | ||
|
||
--- | ||
|
||
## Config | ||
|
||
```ts | ||
interface VitePluginMswOptions { | ||
handlers: RequestHandler[]; | ||
mode?: 'browser' | 'node'; | ||
build?: boolean; | ||
} | ||
``` | ||
|
||
### Handlers | ||
|
||
- Required | ||
|
||
MSW handlers. More information on how to define these: https://mswjs.io/docs/getting-started/mocks | ||
|
||
### Mode | ||
|
||
- Optional | ||
- Default: `browser` | ||
|
||
#### Browser | ||
|
||
To start MSW in the client, please follow the [Configure worker step](https://mswjs.io/docs/getting-started/integrate/browser#configure-worker) and [Start worker step](https://mswjs.io/docs/getting-started/integrate/browser#start-worker) in the MSW docs. The `mockServiceWorker.js` file will be provided by the Vite Dev Server. | ||
|
||
#### Node | ||
|
||
This will handle the mocked service worker handlers via a Vite Dev Server plugin. | ||
|
||
### Build | ||
|
||
- Optional | ||
- Default: `false` | ||
|
||
A true value will output MSW's `mockServiceWorker.js` file to the Vite build directory, in case if MSW is needed in production. | ||
|
||
--- | ||
|
||
## Development | ||
|
||
``` | ||
npm run dev | ||
``` | ||
|
||
### Example vite application with plugin | ||
|
||
``` | ||
npm run build | ||
cd examples/with-vite | ||
npm run dev | ||
curl http://localhost:3000/api/health | ||
``` | ||
|
||
### Build | ||
|
||
``` | ||
npm run build | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "@admin-pkg/mock-server", | ||
"name": "@admin-pkg/vite-plugin-msw", | ||
"version": "0.0.1", | ||
"description": "", | ||
"module": "./dist/browser/index.mjs", | ||
|
@@ -19,11 +19,28 @@ | |
"dev": "rimraf dist && tsup --watch", | ||
"build": "rimraf dist && tsup" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"keywords": [ | ||
"msw", | ||
"mock", | ||
"vite" | ||
], | ||
"author": { | ||
"name": "buqiyuan", | ||
"email": "[email protected]", | ||
"url": "https://github.com/buqiyuan" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/buqiyuan/vue3-antdv-admin/tree/main/packages/vite-plugin-msw", | ||
"directory": "packages/vite-plugin-msw" | ||
}, | ||
"homepage": "https://buqiyuan.github.io/vue3-antdv-admin/tree/main/packages/vite-plugin-msw#readme", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@mswjs/interceptors": "^0.25.14", | ||
"@mswjs/interceptors": "^0.25.15", | ||
"headers-polyfill": "^4.0.2", | ||
"strict-event-emitter": "^0.5.1" | ||
}, | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.