Better dev server integration

This commit is contained in:
MICHAEL JACKSON
2018-02-16 16:00:06 -08:00
parent a22e0fa801
commit d6f2bc089a
42 changed files with 1753 additions and 1154 deletions

View File

@ -0,0 +1,26 @@
/**
* An express middleware that sets req.manifest from the build manifest
* in the given file. Should be used in production together with
* https://github.com/soundcloud/chunk-manifest-webpack-plugin
* to get consistent hashes.
*/
function assetsManifest(webpackManifestFile) {
let manifest;
try {
manifest = JSON.parse(fs.readFileSync(webpackManifestFile, "utf8"));
} catch (error) {
invariant(
false,
'assetsManifest middleware cannot read the manifest file "%s"; ' +
"run `yarn build` before starting the server",
webpackManifestFile
);
}
return (req, res, next) => {
req.manifest = manifest;
next();
};
}
module.exports = assetsManifest;