@@ -200,32 +200,64 @@ interact with the middleware at runtime:
200200
201201### ` close(callback) `
202202
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.
204204
205- ### Parameters
205+ #### Parameters
206206
207- #### callback
207+ ##### ` callback `
208208
209209Type: ` Function `
210+ Required: ` No `
210211
211212A function executed once the middleware has stopped watching.
212213
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+ ```
214232
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.
217245
218246``` js
247+ const express = require (' express' );
219248const webpack = require (' webpack' );
220- const compiler = webpack ({ ... });
249+ const compiler = webpack ({
250+ /* Webpack configuration */
251+ });
221252const middleware = require (' webpack-dev-middleware' );
222253const instance = middleware (compiler);
223254
255+ const app = new express ();
256+
224257app .use (instance);
225258
226259setTimeout (() => {
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
229261 new webpack.BannerPlugin (' A new banner' ).apply (compiler);
230262
231263 // Recompile the bundle with the banner plugin:
@@ -238,28 +270,67 @@ setTimeout(() => {
238270Executes a callback function when the compiler bundle is valid, typically after
239271compilation.
240272
241- ### Parameters
273+ #### Parameters
242274
243- #### callback
275+ ##### ` callback `
244276
245277Type: ` Function `
278+ Required: ` No `
246279
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.
249282
250283``` js
284+ const express = require (' express' );
251285const webpack = require (' webpack' );
252- const compiler = webpack ({ ... });
286+ const compiler = webpack ({
287+ /* Webpack configuration */
288+ });
253289const middleware = require (' webpack-dev-middleware' );
254290const instance = middleware (compiler);
255291
292+ const app = new express ();
293+
256294app .use (instance);
257295
258296instance .waitUntilValid (() => {
259297 console .log (' Package is in a valid state' );
260298});
261299```
262300
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+
263334## Known Issues
264335
265336### Multiple Successive Builds
@@ -289,13 +360,16 @@ process is finished with server-side rendering enabled._
289360Example Implementation:
290361
291362``` js
363+ const express = require (' express' );
292364const webpack = require (' webpack' );
293365const compiler = webpack ({
294- // webpack options
366+ /* Webpack configuration */
295367});
296368const isObject = require (' is-object' );
297369const middleware = require (' webpack-dev-middleware' );
298370
371+ const app = new express ();
372+
299373// This function makes server rendering of asset references consistent with different webpack chunk/entry configurations
300374function normalizeAssets (assets ) {
301375 if (isObject (assets)) {
0 commit comments