text: 'use strict'
  
  const { resolve } = require('path')
  const merge = require('webpack-merge')
  const HtmlWebpackPlugin = require('html-webpack-plugin')
  const CleanWebpackPlugin = require('clean-webpack-plugin')
  
  const ENV = process.argv.find(arg => arg.includes('production'))
    ? 'production'
    : 'development'
  const OUTPUT_PATH = ENV === 'production' ? resolve('dist') : resolve('src')
  const INDEX_TEMPLATE = resolve('./index.html')
  
  const commonConfig = merge([
    {
      entry: './example-app.js',
      output: {
        path: OUTPUT_PATH,
        filename: '[name].[chunkhash:8].js'
      },
      module: {
        rules: [
          {
            test: /\.css$/,
            use: [
              'to-string-loader',
              'css-loader'
            ]
          },
          {
            test: /\.(png|ttf|woff2|woff|eot|svg)$/,
            use: [
              'file-loader'
            ]
          }
        ]
      }
    }
  ])
  
  const developmentConfig = merge([
    {
      devtool: 'cheap-module-source-map',
      plugins: [
        new HtmlWebpackPlugin({
          template: INDEX_TEMPLATE
        })
      ],
  
      devServer: {
        contentBase: OUTPUT_PATH,
        compress: true,
        overlay: true,
        port: 3000,
        historyApiFallback: true,
        host: 'localhost'
      }
    }
  ])
  
  const productionConfig = merge([
    {
      devtool: 'nosources-source-map',
      plugins: [
        new CleanWebpackPlugin([OUTPUT_PATH], { verbose: true }),
        new HtmlWebpackPlugin({
          template: INDEX_TEMPLATE,
          minify: {
            collapseWhitespace: true,
            removeComments: true,
            minifyCSS: true,
            minifyJS: true
          }
        })
      ]
    }
  ])
  
  module.exports = mode => {
    if (mode === 'production') {
      return merge(commonConfig, productionConfig, { mode })
    }
  
    return merge(commonConfig, developmentConfig, { mode })
  }
  