const {readFileSync} = require('fs')
const {resolve} = require('path')

function createRequestDecorator (stats) {
  return (req, res, next) => {
    res.locals = res.locals || Object.create(null)
    res.locals.webpackClientStats = stats

    next && next()
  }
}

function serveAssets (router, options = {}) {
  if (typeof options === 'string') {
    options = {outputPath: options}
  }

  if (typeof arguments[2] === 'function') {
    options.requestDecorator = arguments[2]
  }

  const {
    hideStats = true,
    outputPath,
    publicPath = '/',
    statsFilename = 'stats.json',
    serveStatic,
    requestDecorator = createRequestDecorator
  } = options

  const statsPath = resolve(outputPath, statsFilename)
  const stats = JSON.parse(readFileSync(statsPath, 'utf8'))

  const decorateRequest = requestDecorator(stats)
  const serve = serveStatic(outputPath)

  if (hideStats) {
    router.use(publicPath + statsFilename, (req, res) => {
      res.sendStatus(403)
    })
  }

  router.use(publicPath, serve)
  router.use(decorateRequest)
}

exports = module.exports = serveAssets.bind()
exports.createRequestDecorator = createRequestDecorator
exports.serveAssets = serveAssets

@@ -485,16 +485,43 @@
 const %7B%0A
+    hideSourceMaps = true,%0A
     hide
@@ -891,16 +891,196 @@
 tPath)%0A%0A
+  if (hideSourceMaps) %7B%0A    router.use(publicPath, (req, res, next) =%3E %7B%0A      if (req.url.endsWith('.map')) %7B%0A        return res.sendStatus(403)%0A      %7D%0A%0A      next()%0A    %7D)%0A  %7D%0A%0A
   if (hi

Add option hideSourceMaps to hide source maps