WebPack

WebPack#

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const baseConfig = require('../../shared/base.webpack.js');

module.exports = (env, argv) => {
  const config = baseConfig(env, argv);
  const isProd = argv.mode === 'production';
  
  // Determine output path based on mode
  const outputPath = isProd 
    ? path.resolve(__dirname, '../../../dist/var/www/engineering-exact')  // Production build
    : path.resolve(__dirname, '../../../build/var/www/engineering-exact'); // Development build
  
  return {
    ...config,
    entry: {
      home: path.resolve('main.tsx'),
    },
    output: {
      filename: isProd ? 'app.[contenthash].js' : 'app.js',
      path: outputPath,
      clean: true,
      publicPath: '/',
    },
    resolve: {
      ...config.resolve,
      alias: {
        '@components': path.resolve(__dirname, './components'),
        '@components/*': path.resolve(__dirname, './components'),
        '@shared': path.resolve(__dirname, '../../shared'),
        '@shared/*': path.resolve(__dirname, '../../shared'),
        '@img': path.resolve(__dirname, './assets/img'),
        '@img/*': path.resolve(__dirname, './assets/img'),
      },
    },
    plugins: [
      new HtmlWebpackPlugin({
        title: 'exact.engineering',
        template: path.resolve('index.html'),
        filename: 'index.html',
        favicon: path.resolve('./assets/img/Exact_Controls_logo_icon.svg'),
        inject: true,
        publicPath: './',
        minify: isProd ? {
          removeComments: true,
          collapseWhitespace: true,
          removeRedundantAttributes: true,
        } : false,
      }),
    ],
  };
};