Skip to content

Commit 1a285fb

Browse files
Added an example of the use of res.locals.fs
1 parent eec6d37 commit 1a285fb

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,17 +337,21 @@ app.use(middleware(compiler, { serverSideRender: true }))
337337
// The following middleware would not be invoked until the latest build is finished.
338338
app.use((req, res) => {
339339
const assetsByChunkName = res.locals.webpackStats.toJson().assetsByChunkName
340+
const fs = res.locals.fs
341+
const outputPath = res.locals.webpackStats.toJson().outputPath
340342

341343
// then use `assetsByChunkName` for server-sider rendering
342344
// For example, if you have only one main chunk:
343345
res.send(`
344346
<html>
345347
<head>
346348
<title>My App</title>
349+
<style>
347350
${normalizeAssets(assetsByChunkName.main)
348351
.filter(path => path.endsWith('.css'))
349-
.map(path => `<link rel="stylesheet" href="${path}" />`)
352+
.map(path => fs.readFileSync(outputPath + '/' + path))
350353
.join('\n')}
354+
</style>
351355
</head>
352356
<body>
353357
<div id="root"></div>

0 commit comments

Comments
 (0)