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

module.exports = {
    entry: './src/main.ts',
    
    // Module rules define how different file types are processed
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                use: 'ts-loader',
                exclude: /node_modules/,
            },
        ],
    },
    
    // Resolve configuration for module resolution
    resolve: {
        extensions: ['.ts', '.js'],
        alias: {
            // @helpers can be used instead of relative paths to the helpers directory
            '@helpers': path.resolve(__dirname, '../helpers')
        }
    },
    
    // Output configuration for bundled files
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, './build'),
    },
    
    // Webpack plugins that extend webpack's functionality
    plugins: [
        // Generates HTML file and automatically injects bundled JavaScript
        new HtmlWebpackPlugin({
            template: './index.html',
            favicon: './favicon.ico'
        })
    ]
};