@@ -198,49 +198,73 @@ middleware(compiler, { outputFileSystem: myOutputFileSystem });
198
198
` webpack-dev-middleware ` also provides convenience methods that can be use to
199
199
interact with the middleware at runtime:
200
200
201
- ### ` close(callback? ) `
201
+ ### ` close(callback) `
202
202
203
203
Instructs ` webpack-dev-middleware ` instance to stop watching for file changes.
204
204
205
- ### Parameters
205
+ #### Parameters
206
206
207
- #### callback
207
+ ##### ` callback `
208
208
209
209
Type: ` Function `
210
+ Required: ` No `
210
211
211
212
A function executed once the middleware has stopped watching.
212
213
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
-
218
214
``` js
215
+ const express = require (' express' );
219
216
const webpack = require (' webpack' );
220
- const compiler = webpack ();
217
+ const compiler = webpack ({
218
+ /* Webpack configuration */
219
+ });
221
220
const middleware = require (' webpack-dev-middleware' );
222
221
const instance = middleware (compiler);
223
222
223
+ const app = new express ();
224
+
224
225
app .use (instance);
225
226
226
227
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 ();
233
230
}, 1000 );
234
231
```
235
232
236
- ### Parameters
233
+ ### ` invalidate(callback) `
237
234
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
239
240
240
241
Type: ` Function `
242
+ Required: ` No `
241
243
242
244
A function executed once the middleware has invalidated.
243
245
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
+
244
268
### ` waitUntilValid(callback) `
245
269
246
270
Executes a callback function when the compiler bundle is valid, typically after
@@ -251,16 +275,22 @@ compilation.
251
275
#### callback
252
276
253
277
Type: ` Function `
278
+ Required: ` No `
254
279
255
280
A function executed when the bundle becomes valid.
256
281
If the bundle is valid at the time of calling, the callback is executed immediately.
257
282
258
283
``` js
284
+ const express = require (' express' );
259
285
const webpack = require (' webpack' );
260
- const compiler = webpack ();
286
+ const compiler = webpack ({
287
+ /* Webpack configuration */
288
+ });
261
289
const middleware = require (' webpack-dev-middleware' );
262
290
const instance = middleware (compiler);
263
291
292
+ const app = new express ();
293
+
264
294
app .use (instance);
265
295
266
296
instance .waitUntilValid (() => {
@@ -272,12 +302,26 @@ instance.waitUntilValid(() => {
272
302
273
303
Get filename from URL.
274
304
305
+ ### Parameters
306
+
307
+ #### url
308
+
309
+ Type: ` String `
310
+ Required: ` Yes `
311
+
312
+ URL for the requested file.
313
+
275
314
``` js
315
+ const express = require (' express' );
276
316
const webpack = require (' webpack' );
277
- const compiler = webpack ();
317
+ const compiler = webpack ({
318
+ /* Webpack configuration */
319
+ });
278
320
const middleware = require (' webpack-dev-middleware' );
279
321
const instance = middleware (compiler);
280
322
323
+ const app = new express ();
324
+
281
325
app .use (instance);
282
326
283
327
instance .waitUntilValid (() => {
@@ -316,13 +360,16 @@ process is finished with server-side rendering enabled._
316
360
Example Implementation:
317
361
318
362
``` js
363
+ const express = require (' express' );
319
364
const webpack = require (' webpack' );
320
365
const compiler = webpack ({
321
- // webpack options
366
+ /* Webpack configuration */
322
367
});
323
368
const isObject = require (' is-object' );
324
369
const middleware = require (' webpack-dev-middleware' );
325
370
371
+ const app = new express ();
372
+
326
373
// This function makes server rendering of asset references consistent with different webpack chunk/entry configurations
327
374
function normalizeAssets (assets ) {
328
375
if (isObject (assets)) {
0 commit comments