const path = require("path");
const webpack = require('webpack');
const Dotenv = require("dotenv-webpack");

const environment = process.env.ENVIRONMENT || 'development';
const node_env = process.env.NODE_ENV || 'development';
    
module.exports = {
  entry: "./client-hydrate.js",
  output: {
    path: path.resolve(__dirname, "..", "public", "js"),
    filename: "client-hydrate.bundle.js",
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
            presets: [
              '@babel/preset-env',
              '@babel/preset-react'
            ]
          }
        },
      },
      {
        test: /\.svg/, 
        type: 'asset/inline'
      },
      {
        test: /\.(png|jpe?g|gif)$/i,
        type: 'asset',
      }
    ],
  },
  resolve: {
    extensions: [".js", ".jsx"],
    alias: {
      react: path.resolve('./node_modules/react'),
    }
  },
  devtool: 'eval-source-map',
  mode: node_env,
  plugins: [
    new Dotenv({
      path: `../.env.${environment}`
    })
  ],
  optimization: {
    minimize: node_env === 'production', //only minimize in production
  },
};
