diff --git a/README.md b/README.md index 321cc1b81..91a9cf060 100644 --- a/README.md +++ b/README.md @@ -309,7 +309,7 @@ In order to develop an app using server-side rendering, we need access to the generated with each build. With server-side rendering enabled, `webpack-dev-middleware` sets the `stat` to -`res.locals.webpackStats` before invoking the next middleware, allowing a +`res.locals.webpackStats` and the memory filesystem to `res.locals.fs` before invoking the next middleware, allowing a developer to render the page body and manage the response to clients. _Note: Requests for bundle files will still be handled by @@ -337,6 +337,8 @@ app.use(middleware(compiler, { serverSideRender: true })) // The following middleware would not be invoked until the latest build is finished. app.use((req, res) => { const assetsByChunkName = res.locals.webpackStats.toJson().assetsByChunkName + const fs = res.locals.fs + const outputPath = res.locals.webpackStats.toJson().outputPath // then use `assetsByChunkName` for server-sider rendering // For example, if you have only one main chunk: @@ -344,10 +346,12 @@ app.use((req, res) => { My App +
diff --git a/lib/middleware.js b/lib/middleware.js index 23e2220cf..2813bd6ab 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -19,6 +19,7 @@ module.exports = function wrapper(context) { return new Promise(((resolve) => { ready(context, () => { res.locals.webpackStats = context.webpackStats; + res.locals.fs = context.fs; resolve(next()); }, req); })); diff --git a/test/tests/server.js b/test/tests/server.js index 5d7419665..ceb685c8d 100644 --- a/test/tests/server.js +++ b/test/tests/server.js @@ -339,6 +339,7 @@ describe('Server', () => { request(app).get('/foo/bar') .expect(200, () => { assert(locals.webpackStats); + assert(locals.fs); done(); }); });