markdalgleish / static-site-generator-webpack-plugin

Minimal, unopinionated static site generator powered by webpack
MIT License
1.61k stars 97 forks source link

Request: Add support for a 'render-time' method to manipulate locals #121

Open jahredhope opened 6 years ago

jahredhope commented 6 years ago

Isolating Webpack Logic

Currently this plugin passes the webpackStats object directly to the render function. This can be helpful when assets is not enough information to render.

However it can result in webpack specific logic being added to the render function. For example:

  const publicPath = webpackStats.compilation.outputOptions.publicPath;
  const clientJsEntry = assetsByChunkName.main
    .filter(value => value.match(/\.js/))
    .map(value => `${publicPath}${value}`)[0];
  const clientCssEntry = assetsByChunkName.main
    .filter(value => value.match(/\.css$/))
    .map(value => `${publicPath}${value}`)[0];

By adding a runtime transform function the logic required to pull data out of webpackStats object can be isolated to the webpack configuration. This may be particularly useful for tools that wrap this plugin, which may choose to use the function to normalize the parameters being given to their consumer's render function.

'Render-time' build info

Separately, information required to render the HTML may not be available when the configuration is first built. A render-time transform function will allow values created during the build process (such as peer webpack configurations) to be injected into the render process.