var webpack = require('webpack')
var config = require('./webpack.base.conf')
var HtmlWebpackPlugin = require('html-webpack-plugin')

// eval-source-map is faster for development
config.devtool = 'eval-source-map'

// add hot-reload related code to entry chunk
config.entry.app = [
  'eventsource-polyfill',
  'webpack-hot-middleware/client?quiet=true',
  config.entry.app
]

// necessary for the html plugin to work properly
// when serving the html from in-memory
config.output.publicPath = '/'

config.plugins = (config.plugins || []).concat([
  // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
  new webpack.optimize.OccurenceOrderPlugin(),
  new webpack.HotModuleReplacementPlugin(),
  new webpack.NoErrorsPlugin(),
  // https://github.com/ampedandwired/html-webpack-plugin
  new HtmlWebpackPlugin({
    filename: 'index.html',
    template: 'src/index.html'
  })
])

module.exports = config

@@ -256,31 +256,24 @@
 hunk
-%0Aconfig.entry.app = %5B%0A 
+s%0Avar polyfill =
  'ev
@@ -291,19 +291,32 @@
 olyfill'
-,%0A 
+%0Avar hotClient =
  'webpac
@@ -354,30 +354,184 @@
 rue'
-,%0A  config.entry.app%0A%5D
+%0AObject.keys(config.entry).forEach(function (name, i) %7B%0A  var extras = i === 0 ? %5Bpolyfill, hotClient%5D : %5BhotClient%5D%0A  config.entry%5Bname%5D = extras.concat(config.entry%5Bname%5D)%0A%7D)
 %0A%0A//

add hot reload client to all entry chunks