const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = env => {
  console.info(`Building for '${env.NODE_ENV}'.`);

  const isDev =
    env.NODE_ENV === 'development' || env.NODE_ENV === 'local_stage';

  return {
    mode: 'development',
    entry: './src/index.js',
    devtool: 'inline-source-map',
    devServer: {
      contentBase: './dist',
      https: true,
      host: '0.0.0.0',
      port: 1234,
      hot: false,
      inline: false,
    },
    output: {
      filename: 'main.js',
      path: path.resolve(__dirname, 'dist'),
    },
    plugins: [
      new HtmlWebpackPlugin({
        hash: true,
        template: './src/index.html',
        filename: './index.html',
        isDev,
      }),
      new webpack.EnvironmentPlugin({
        NODE_ENV: env.NODE_ENV,
      }),
    ],
  };
};
