const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
  entry: ['./src/client/index.ts', './src/client/scss/index.scss'],
  module: {
    rules: [
      {
        test: /\.(ts|js)?$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env', '@babel/preset-typescript',],
          },
        },
      },
      {
        test: /\.(css|scss)/,
        use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
      },
    ],
  },
  resolve: {
    extensions: ['.ts', '.js'],
  },
  plugins: [new HtmlWebpackPlugin({
    title: 'Icy3D World Experiment'
  }), new MiniCssExtractPlugin()],
  output: {
    path: path.resolve(__dirname, 'dist', 'public'),
    filename: 'bundle.js',
  },
  devtool: process.env.NODE_ENV !== 'production' ? 'source-map' : undefined,
};
