glints-dev / hapi-webpack-dev-server-plugin

webpack-dev-server plugin for hapi
2 stars 0 forks source link

How to access stats for SSR options #9

Open empeje opened 5 years ago

empeje commented 5 years ago

I'm following https://github.com/webpack/webpack-dev-middleware#server-side-rendering for SSR options of webpack-dev-middleware, but I can't get the stats object from the plugin. I also new to hapi, so I don't know how to access it.

yjwong commented 5 years ago

Hello @empeje!

The plugin exposes the underlying webpack-dev-middleware using Hapi's server.expose() API. This means, you can access it through server.plugins.WebpackDevServerPlugin.devMiddleware.

For example:

hapiServer.ext('onRequest', (request, h) => {
  const devMiddleware = hapiServer.plugins.WebpackDevServerPlugin.devMiddleware;
  devMiddleware.waitUntilValid((stats) => {
    // Do something with stats here...
  });
  return h.continue;
});