# vite-easy-mock

> mock server

Latest version **1.0.9** (published 2023-01-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install vite-easy-mock
pnpm add vite-easy-mock
yarn add vite-easy-mock
bun add vite-easy-mock
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.9 |
| Published | 2023-01-17 |
| First published | 2022-08-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 4 |
| Author | iceqing |
| Maintainers | iceqing |
| Keywords | vite, vite-plugin, mock, typescript, vite-easy-mock |

## Links

- npm: https://www.npmjs.com/package/vite-easy-mock
- Repository: https://github.com/iceqing/vite-easy-mock
- Homepage: https://github.com/iceqing/vite-easy-mock#readme
- Issues: https://github.com/iceqing/vite-easy-mock/issues
- npm.io page: https://npm.io/package/vite-easy-mock

## Dependencies (1)

- [esbuild](https://npm.io/package/esbuild.md) 0.11.3

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.9 (latest) — 2023-01-17
- 1.0.7-beta.1 (beta) — 2022-09-15
- 1.0.8 — 2022-11-03
- 1.0.7 — 2022-09-17
- 1.0.7-beta.0 — 2022-09-15
- 1.0.6 — 2022-08-20
- 1.0.5 — 2022-08-16
- 1.0.4 — 2022-08-16
- 1.0.3 — 2022-08-16
- 1.0.2 — 2022-08-16
- 1.0.1 — 2022-08-16
- 1.0.0-bata.1 — 2022-08-16
- 1.0.0-bate.1 — 2022-08-16
- 1.0.0 — 2022-08-16

## README

# vite-easy-mock


> 本仓库参考[vite-plugin-easy-mock](https://github.com/leitingting08/vite-plugin-easy-mock), 对部分功能做了修复增强, 比如`fileSuffix`参数支持，找不到路由时默认跳过等。

## Install

```bash
yarn add vite-easy-mock --dev
# or
npm i vite-easy-mock --save-dev
```

## Usage

vite.config.js

```js
import { defineConfig } from 'vite'
import viteMock from 'vite-easy-mock'

export default defineConfig({
  plugins: [
    viteMock()
  ]
})
```

vue.config.js 中使用

```js
const { useMiddleWare } = require('vite-easy-mock')

module.exports = {
  devServer: {
    before (app) {
      // 使用mock中间件
      app.use(useMiddleWare())
    }
  },
}
```

根目录下新建 `mock` 文件夹，新建文件夹和 json 或者 js 文件

文件夹和文件名配合就能 mock 本地 `/user/getAuthList` 接口，json 和 js 写法如下：

`mock/user/getAuthList.json`

```json
{
  "success": true,
  "desc": null,
  "data": []
}
```

`mock/user/getAuthList.js`

```js
module.export = (req) => {
  // 打印所有的query参数
  console.log("req.query", req.query);
  return {
    success: true,
    desc: null,
    data: []
  }
}
```

---
_Source: https://npm.io/package/vite-easy-mock · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
