Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nulldef committed Aug 16, 2021
1 parent fc075fb commit de91424
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# DevMock

Webpack Dev Server mocking engine

## Install

```sh
npm i --save devmock
```

or

```sh
yarn add devmock
```

And require it for further usage
```js
const { DevMock } = require("devmock")
```

## Usage

### For `webpack-dev-server` < `4.0`

```js
devServer: {
before: DevMock.v3({
mocksPath: path.resolve("mocks/**/*.mock.js")
})
}
```

### For `webpack-dev-server` >= `4.0`

```js
devServer: {
onBeforeSetupMiddleware: DevMock.make({
mocksPath: path.resolve("mocks/**/*.mock.js")
})
}
```
11 changes: 10 additions & 1 deletion lib/DevMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@ class DevMock {
return new DevMock(...args).middleware
}

static v3(...args) {
return new DevMock(...args).v3Middleware
}

constructor({ mocksPath }) {
this.files = glob.sync(mocksPath)
}

middleware = ({ app, options, logger }) => {
middleware = (...args) => this.v4middleware(...args)

v3Middleware = (app, { headers }) => this.v4middleware({ app, options: { headers }})

v4middleware = ({ app, options }) => {
const { headers } = options
const logger = console

app.use(express.json())

Expand Down

0 comments on commit de91424

Please sign in to comment.