Skip to content

Commit 3ba2fbe

Browse files
docs: improve
1 parent 5702b1b commit 3ba2fbe

File tree

1 file changed

+67
-20
lines changed

1 file changed

+67
-20
lines changed

README.md

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -198,49 +198,73 @@ middleware(compiler, { outputFileSystem: myOutputFileSystem });
198198
`webpack-dev-middleware` also provides convenience methods that can be use to
199199
interact with the middleware at runtime:
200200

201-
### `close(callback?)`
201+
### `close(callback)`
202202

203203
Instructs `webpack-dev-middleware` instance to stop watching for file changes.
204204

205-
### Parameters
205+
#### Parameters
206206

207-
#### callback
207+
##### `callback`
208208

209209
Type: `Function`
210+
Required: `No`
210211

211212
A function executed once the middleware has stopped watching.
212213

213-
### `invalidate(callback?)`
214-
215-
Instructs a webpack-dev-middleware instance to recompile the bundle.
216-
e.g. after a change to the configuration.
217-
218214
```js
215+
const express = require('express');
219216
const webpack = require('webpack');
220-
const compiler = webpack();
217+
const compiler = webpack({
218+
/* Webpack configuration */
219+
});
221220
const middleware = require('webpack-dev-middleware');
222221
const instance = middleware(compiler);
223222

223+
const app = new express();
224+
224225
app.use(instance);
225226

226227
setTimeout(() => {
227-
// After a short delay the configuration is changed and a banner plugin is added
228-
// to the config
229-
new webpack.BannerPlugin('A new banner').apply(compiler);
230-
231-
// Recompile the bundle with the banner plugin:
232-
instance.invalidate();
228+
// Says `webpack` to stop watch changes
229+
instance.close();
233230
}, 1000);
234231
```
235232

236-
### Parameters
233+
### `invalidate(callback)`
237234

238-
#### callback
235+
Instructs `webpack-dev-middleware` instance to recompile the bundle, e.g. after a change to the configuration.
236+
237+
#### Parameters
238+
239+
##### callback
239240

240241
Type: `Function`
242+
Required: `No`
241243

242244
A function executed once the middleware has invalidated.
243245

246+
```js
247+
const express = require('express');
248+
const webpack = require('webpack');
249+
const compiler = webpack({
250+
/* Webpack configuration */
251+
});
252+
const middleware = require('webpack-dev-middleware');
253+
const instance = middleware(compiler);
254+
255+
const app = new express();
256+
257+
app.use(instance);
258+
259+
setTimeout(() => {
260+
// After a short delay the configuration is changed and a banner plugin is added to the config
261+
new webpack.BannerPlugin('A new banner').apply(compiler);
262+
263+
// Recompile the bundle with the banner plugin:
264+
instance.invalidate();
265+
}, 1000);
266+
```
267+
244268
### `waitUntilValid(callback)`
245269

246270
Executes a callback function when the compiler bundle is valid, typically after
@@ -251,16 +275,22 @@ compilation.
251275
#### callback
252276

253277
Type: `Function`
278+
Required: `No`
254279

255280
A function executed when the bundle becomes valid.
256281
If the bundle is valid at the time of calling, the callback is executed immediately.
257282

258283
```js
284+
const express = require('express');
259285
const webpack = require('webpack');
260-
const compiler = webpack();
286+
const compiler = webpack({
287+
/* Webpack configuration */
288+
});
261289
const middleware = require('webpack-dev-middleware');
262290
const instance = middleware(compiler);
263291

292+
const app = new express();
293+
264294
app.use(instance);
265295

266296
instance.waitUntilValid(() => {
@@ -272,12 +302,26 @@ instance.waitUntilValid(() => {
272302

273303
Get filename from URL.
274304

305+
### Parameters
306+
307+
#### url
308+
309+
Type: `String`
310+
Required: `Yes`
311+
312+
URL for the requested file.
313+
275314
```js
315+
const express = require('express');
276316
const webpack = require('webpack');
277-
const compiler = webpack();
317+
const compiler = webpack({
318+
/* Webpack configuration */
319+
});
278320
const middleware = require('webpack-dev-middleware');
279321
const instance = middleware(compiler);
280322

323+
const app = new express();
324+
281325
app.use(instance);
282326

283327
instance.waitUntilValid(() => {
@@ -316,13 +360,16 @@ process is finished with server-side rendering enabled._
316360
Example Implementation:
317361

318362
```js
363+
const express = require('express');
319364
const webpack = require('webpack');
320365
const compiler = webpack({
321-
// webpack options
366+
/* Webpack configuration */
322367
});
323368
const isObject = require('is-object');
324369
const middleware = require('webpack-dev-middleware');
325370

371+
const app = new express();
372+
326373
// This function makes server rendering of asset references consistent with different webpack chunk/entry configurations
327374
function normalizeAssets(assets) {
328375
if (isObject(assets)) {

0 commit comments

Comments
 (0)