import HtmlWebpackPlugin from 'html-webpack-plugin'

const defaultPages = ['index']
const hotMiddleware = 'webpack-hot-middleware/client'

export default {
  name: 'webpack-pages',
  configure ({ buildTarget, pages = defaultPages }) {
    const plugins = pages.map(page => {
      return new HtmlWebpackPlugin({
        template: `src/${page}.html`,
        filename: `${page}.html`,
        chunks: ['common', page]
      })
    })

    let entry = {}
    pages.forEach(page => {
      entry[page] = [`./src/${page}`]

      if (buildTarget === 'develop') {
        entry[page].push(hotMiddleware)
      }
    })

    return { plugins, entry }
  }
}

@@ -72,15 +72,8 @@
  = %5B
-'index'
 %5D%0Aco

Disable pages by default if not configured