Gathering detailed insights and metrics for vite-plugin-best-mock
Gathering detailed insights and metrics for vite-plugin-best-mock
Gathering detailed insights and metrics for vite-plugin-best-mock
Gathering detailed insights and metrics for vite-plugin-best-mock
npm install vite-plugin-best-mock
Typescript
Module System
Node Version
NPM Version
6.3
Supply Chain
61.3
Quality
68.8
Maintenance
25
Vulnerability
95
License
TypeScript (96.92%)
HTML (2.36%)
JavaScript (0.72%)
Total Downloads
879
Last Day
1
Last Week
2
Last Month
7
Last Year
153
2 Stars
22 Commits
1 Watchers
3 Branches
1 Contributors
Updated on Nov 04, 2022
Latest Version
0.0.6
Package Id
vite-plugin-best-mock@0.0.6
Unpacked Size
6.20 kB
Size
2.16 kB
File Count
3
NPM Version
6.14.17
Node Version
14.20.0
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
100%
2
Compared to previous week
Last Month
-72%
7
Compared to previous month
Last Year
14.2%
153
Compared to previous year
6
6
English | 中文
[![npm][npm-img]][npm-url] [![node][node-img]][node-url]
Provide local and prod mocks for vite.
A mock plugin for vite, and support the local environment and production environment at the same time. Connect service middleware is used locally, runtime not yet implemented.
node version: >=12.0.0
vite version: >=2.0.0
1yarn add vite-plugin-best-mock -D 2# or 3npm i vite-plugin-best-mock -D
Run Example
1# ts example 2cd playground 3 4yarn install 5 6yarn dev
Development environment
The development environment is implemented using Connect middleware。
Different from the production environment, you can view the network request record in the Google Chrome console
1import { UserConfigExport, ConfigEnv } from 'vite' 2 3import { mockPlugin } from 'vite-plugin-mock' 4 5export default ({ command }: ConfigEnv): UserConfigExport => { 6 return { 7 plugins: [ 8 vue(), 9 mockPlugin(), 10 ], 11 } 12}
1interface MockPluginConfig { 2 dir?: string; 3 prefix?: string; 4 timeout?: [number, number]; 5 multiparty: MultipartyConfig; 6}
type: string
default: 'mock'
Set the folder where the mock .ts file is stored
type: string
default: '/api/'
the url start with prefix will be mocked
type: boolean
default: command === 'serve'
Set whether to enable the local mock .ts file, do not open it in the production environment
type: boolean
default: command !=='serve'
Set whether to enable mock function for packaging
type: MultipartyConfig
default: {}
If you pass multiparty to mockPlugin(), they are passed directly into multiparty.
/path/mock
1// user.ts 2 3import { MockMethod } from 'vite-plugin-best-mock' 4 5/** 6 * url: /user 7 * method: get 8 */ 9export const get: MockMethod = (req) => { 10 const { id } = req.query || {}; 11 return { 12 id, 13 name: 'qingyang', 14 }; 15}; 16 17/** 18 * url: /user 19 * method: post 20 */ 21export const post: MockMethod = (req) => { 22 const { id } = req.body || {}; 23 return { 24 id, 25 name: 'qingyang', 26 }; 27};
1export interface MockMethod { 2 (req: Req, res: Res): any; 3 timeout?: Pick<MockConfig, "timeout">["timeout"]; 4}
you can refer to Next.js Dynamic api routes.
MIT
No vulnerabilities found.
No security vulnerabilities found.