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

const outputDir = 'dist_example';
const publicPath = '/';
const tsConfig = 'tsconfig_example.json';

module.exports = {
    entry: {
        index: [
            // "@babel/polyfill",
            "./src/app/index.ts"
        ]
    },
    output: {
        path: path.resolve(__dirname, outputDir),
        filename: '[name].bundle.js',
        publicPath: publicPath,
        crossOriginLoading: 'anonymous'
    },
    devtool: 'source-map',
    mode: 'development',
    module: {
        rules: [
            {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
            },
            {
                test: /\.tsx?$/,
                use: [
                    {
                        loader: 'ts-loader',
                        options: {
                            configFile: tsConfig
                        }
                    }
                ],
                exclude: /node_modules/
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            title: 'Medsurf PIXI',
            template: 'src/public/index.html',
            hash: true,
            minify: {
                collapseWhitespace: true,
                removeComments: true,
                removeRedundantAttributes: true,
                removeScriptTypeAttributes: true,
                removeStyleLinkTypeAttributes: true,
                useShortDoctype: true
            }
        }),
        new webpack.ProvidePlugin({
            PIXI: 'pixi.js-legacy'
        }),
    ],
    node: {
        net: 'empty',
        tls: 'empty',
        dns: 'empty',
        fs: 'empty',
    },
    resolve: {
        extensions: ['.js', '.ts', '.tsx', '.css', '.scss', '.json'],
        modules: ['node_modules'],
        plugins: []
    },
    stats: 'verbose',
    devServer: {
        contentBase: path.join(__dirname, outputDir),
        compress: false,
        host: '0.0.0.0',
        port: 9000,
        publicPath: publicPath,
        https: false,
        overlay: {
            warnings: true,
            errors: true
        },
        historyApiFallback: true,
        headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
        }
    }
};