manuelbieh / react-ssr-setup

React Starter Project with Webpack 4, Babel 7, TypeScript, CSS Modules, Server Side Rendering, i18n and some more niceties

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: res.locals

kahurangitama opened this issue · comments

commented

Hi! First of all I would thank you for this project, its truly awesome!
Recently I moved to @loadable/component + ssr. But still can't understand one thing in your code:

css={[res.locals.assetPath('bundle.css'), res.locals.assetPath('vendor.css')]}

There is res.locals.assetPath function there. But I can't realize where it appear from? If I do console.log I'll get another functions which I suggest related to chunk extractor or something like that. But I wan't keep my res.locals clean. How can I remove it?

{
user: null // passportjs
store: {...}, // it's store
history: {...}, // it's history
...
// where next func came from?
  getSources: [Function: getSources],
  getStylesheetSources: [Function: getStylesheetSources],
  getStylesheets: [Function: getStylesheets],
  getJavascriptSources: [Function: getJavascriptSources],
  getJavascripts: [Function: getJavascripts],
  getImageSources: [Function: getImageSources],
  getImages: [Function: getImages],
  getManifest: [Function: getManifest],
  assetPath: [Function: assetPath],
  imageTag: [Function: imageTag],
  javascriptTag: [Function: javascriptTag],
  stylesheetTag: [Function: stylesheetTag] }

Search trough project didn't found anything

It’s coming from this plugin/middleware:
https://github.com/danethurber/express-manifest-helpers/blob/master/README.md#helpers

It’s reading the manifest file created by webpack-manifest-plugin in config/webpack.config.js/plugins.js

Used here:

app.use(
manifestHelpers({
manifestPath: `${manifestPath}/manifest.json`,
})
);

commented

Thank you for response! I asked because suddenly assetPath() started to return an empty string and I trying to figure out what I did wrong. Thanks again!

That sometimes happens if there were problems writing the manifest.json. It usually helps to restart the yarn start process.