From eec6d37005620389424cd88884e7bbdea4640f5d Mon Sep 17 00:00:00 2001 From: ferdinando-ferreira Date: Thu, 30 Aug 2018 14:34:33 +0100 Subject: [PATCH 1/3] Pass the memory filesystem to the next middleware along with webpackStats --- lib/middleware.js | 1 + test/tests/server.js | 1 + 2 files changed, 2 insertions(+) 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(); }); }); From 1a285fb0e541ed29a7576294927e6f63eb757c51 Mon Sep 17 00:00:00 2001 From: ferdinando-ferreira Date: Tue, 4 Sep 2018 21:48:51 +0100 Subject: [PATCH 2/3] Added an example of the use of res.locals.fs --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 321cc1b81..bdbf05709 100644 --- a/README.md +++ b/README.md @@ -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 +
From 876e51907de92f7890f62065110f7f3b5223243c Mon Sep 17 00:00:00 2001 From: ferdinando-ferreira Date: Wed, 5 Sep 2018 07:46:41 +0100 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bdbf05709..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