@@ -200,32 +200,64 @@ interact with the middleware at runtime:
200
200
201
201
### ` close(callback) `
202
202
203
- Instructs a webpack-dev-middleware instance to stop watching for file changes.
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() `
214
+ ``` js
215
+ const express = require (' express' );
216
+ const webpack = require (' webpack' );
217
+ const compiler = webpack ({
218
+ /* Webpack configuration */
219
+ });
220
+ const middleware = require (' webpack-dev-middleware' );
221
+ const instance = middleware (compiler);
222
+
223
+ const app = new express ();
224
+
225
+ app .use (instance);
226
+
227
+ setTimeout (() => {
228
+ // Says `webpack` to stop watch changes
229
+ instance .close ();
230
+ }, 1000 );
231
+ ```
214
232
215
- Instructs a webpack-dev-middleware instance to recompile the bundle.
216
- e.g. after a change to the configuration.
233
+ ### ` invalidate(callback) `
234
+
235
+ Instructs ` webpack-dev-middleware ` instance to recompile the bundle, e.g. after a change to the configuration.
236
+
237
+ #### Parameters
238
+
239
+ ##### ` callback `
240
+
241
+ Type: ` Function `
242
+ Required: ` No `
243
+
244
+ A function executed once the middleware has invalidated.
217
245
218
246
``` js
247
+ const express = require (' express' );
219
248
const webpack = require (' webpack' );
220
- const compiler = webpack ({ ... });
249
+ const compiler = webpack ({
250
+ /* Webpack configuration */
251
+ });
221
252
const middleware = require (' webpack-dev-middleware' );
222
253
const instance = middleware (compiler);
223
254
255
+ const app = new express ();
256
+
224
257
app .use (instance);
225
258
226
259
setTimeout (() => {
227
- // After a short delay the configuration is changed and a banner plugin is added
228
- // to the config
260
+ // After a short delay the configuration is changed and a banner plugin is added to the config
229
261
new webpack.BannerPlugin (' A new banner' ).apply (compiler);
230
262
231
263
// Recompile the bundle with the banner plugin:
@@ -238,28 +270,67 @@ setTimeout(() => {
238
270
Executes a callback function when the compiler bundle is valid, typically after
239
271
compilation.
240
272
241
- ### Parameters
273
+ #### Parameters
242
274
243
- #### callback
275
+ ##### ` callback `
244
276
245
277
Type: ` Function `
278
+ Required: ` No `
246
279
247
- A function executed when the bundle becomes valid. If the bundle is
248
- valid at the time of calling, the callback is executed immediately.
280
+ A function executed when the bundle becomes valid.
281
+ If the bundle is valid at the time of calling, the callback is executed immediately.
249
282
250
283
``` js
284
+ const express = require (' express' );
251
285
const webpack = require (' webpack' );
252
- const compiler = webpack ({ ... });
286
+ const compiler = webpack ({
287
+ /* Webpack configuration */
288
+ });
253
289
const middleware = require (' webpack-dev-middleware' );
254
290
const instance = middleware (compiler);
255
291
292
+ const app = new express ();
293
+
256
294
app .use (instance);
257
295
258
296
instance .waitUntilValid (() => {
259
297
console .log (' Package is in a valid state' );
260
298
});
261
299
```
262
300
301
+ ### ` getFilenameFromUrl(url) `
302
+
303
+ Get filename from URL.
304
+
305
+ #### Parameters
306
+
307
+ ##### ` url `
308
+
309
+ Type: ` String `
310
+ Required: ` Yes `
311
+
312
+ URL for the requested file.
313
+
314
+ ``` js
315
+ const express = require (' express' );
316
+ const webpack = require (' webpack' );
317
+ const compiler = webpack ({
318
+ /* Webpack configuration */
319
+ });
320
+ const middleware = require (' webpack-dev-middleware' );
321
+ const instance = middleware (compiler);
322
+
323
+ const app = new express ();
324
+
325
+ app .use (instance);
326
+
327
+ instance .waitUntilValid (() => {
328
+ const filename = instance .getFilenameFromUrl (' /bundle.js' );
329
+
330
+ console .log (` Filename is ${ filename} ` );
331
+ });
332
+ ```
333
+
263
334
## Known Issues
264
335
265
336
### Multiple Successive Builds
@@ -289,13 +360,16 @@ process is finished with server-side rendering enabled._
289
360
Example Implementation:
290
361
291
362
``` js
363
+ const express = require (' express' );
292
364
const webpack = require (' webpack' );
293
365
const compiler = webpack ({
294
- // webpack options
366
+ /* Webpack configuration */
295
367
});
296
368
const isObject = require (' is-object' );
297
369
const middleware = require (' webpack-dev-middleware' );
298
370
371
+ const app = new express ();
372
+
299
373
// This function makes server rendering of asset references consistent with different webpack chunk/entry configurations
300
374
function normalizeAssets (assets ) {
301
375
if (isObject (assets)) {
0 commit comments