# webpack-dev-mock

> Webpack devserver middleware mock server

Latest version **2.0.0** (published 2021-12-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install webpack-dev-mock
pnpm add webpack-dev-mock
yarn add webpack-dev-mock
bun add webpack-dev-mock
```

## Health

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

Positive: no vulnerabilities; popular repo.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2021-12-09 |
| First published | 2018-07-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 14 |
| Unpacked size | 15.1 KB |
| Known vulnerabilities | 0 (+11 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 18615 |
| Author | ice-admin@alibaba-inc.com |
| Maintainers | sobear, noyobo, clarkxia, chenbin93, solojiang, luhengchang228, rax-publisher |

## Links

- npm: https://www.npmjs.com/package/webpack-dev-mock
- Repository: https://github.com/alibaba/ice/tree/master/packages/webpack-dev-mock
- npm.io page: https://npm.io/package/webpack-dev-mock

## Dependencies (14)

- [glob](https://npm.io/package/glob.md) ^7.1.4
- [chalk](https://npm.io/package/chalk.md) ^2.4.1
- [debug](https://npm.io/package/debug.md) ^3.1.0
- [multer](https://npm.io/package/multer.md) ^1.4.2
- [chokidar](https://npm.io/package/chokidar.md) ^3.5.2
- [fs-extra](https://npm.io/package/fs-extra.md) ^9.0.1
- [body-parser](https://npm.io/package/body-parser.md) ^1.18.3
- [@babel/parser](https://npm.io/package/@babel/parser.md) ^7.12.11
- [path-to-regexp](https://npm.io/package/path-to-regexp.md) ^1.7.0
- [@babel/register](https://npm.io/package/@babel/register.md) ^7.12.10
- [@babel/traverse](https://npm.io/package/@babel/traverse.md) ^7.12.12
- [lodash.debounce](https://npm.io/package/lodash.debounce.md) ^4.0.8
- [express-http-proxy](https://npm.io/package/express-http-proxy.md) ^1.2.0
- [@builder/babel-config](https://npm.io/package/@builder/babel-config.md) ^2.0.0

## Recent versions

- 2.0.0 (latest) — 2021-12-09
- 2.0.0-beta.2 (beta) — 2021-12-09
- 1.3.0-rc.4 (next) — 2021-09-17
- 2.0.0-beta.1 — 2021-12-09
- 1.3.2 — 2021-11-25
- 1.3.2-beta.1 — 2021-11-25
- 1.3.1 — 2021-10-21
- 1.3.1-beta.1 — 2021-10-21
- 1.3.1-beta.0 — 2021-10-21
- 1.3.0 — 2021-09-17
- 1.3.0-rc.3 — 2021-09-17
- 1.3.0-rc.2 — 2021-09-10
- 1.3.0-rc.1 — 2021-09-07
- 1.2.1 — 2021-03-17
- 1.2.1-beta.2 — 2021-03-16
- … 23 more at https://npm.io/package/webpack-dev-mock/versions

## README

# mock-dev-server

mock-dev-server 是一个 express 服务的中间件

读取项目目录下的 `mock/index.js` 文件生成，会配置对应的接口。

## 示例

```js
// mock/index.js
const foo = require('./foo.json');
const bar = require('./bar');

module.exports = {
  // 同时支持 GET 和 POST
  '/api/users/1': foo,
  '/api/foo/bar': bar(),

  // 支持标准 HTTP
  'GET /api/users': { users: [1, 2] },
  'DELETE /api/users': { users: [1, 2] },

  // 支持自定义函数，API 参考 express4
  'POST /api/users/create': (req, res) => {
    res.end('OK');
  },

  // 支持参数
  'POST /api/users/:id': (req, res) => {
    const { id } = req.params;
    res.send({ id: id });
  },
};
```

## 服务代码使用方法

```js
// server.js
const express = require('express');

const mockServer = require('mock-server');

const app = express();

mockServer(app);

app.get('/', (req, res) => res.send('hello world'));

app.listen(6001, () => {
  console.log('Example app listening on port 6001!');
  console.log('http://127.0.0.1:6001');
});
```

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