

const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

const debug = true;

module.exports = (env={})=>{

    console.log('run builder with env:',env);

    const clientEntry = {
        'app.bundle':['./sources/index.ts'],
    };


    const clientOutput = {
        path: path.resolve('./release/'),
        filename:'[name].js'
    };

    console.log('webpack started at',new Date());

    let config = {
        entry: clientEntry,
        output: clientOutput,
        mode: 'production',
        resolveLoader: {
            modules: ['node_modules', path.resolve(__dirname, 'sources/node_tools/loaders')]
        },
        watchOptions: {
            poll: true
        },
        performance: {
            maxEntrypointSize: 512000,
            maxAssetSize: 512000
        },
        module: {
            rules: [
                {
                    test: /\.ts$/,
                    loader: "ts-loader",
                    options: {}
                },
                {
                    test: /\.scr$/,
                    loader: "scr-loader",
                    options: {}
                },
                {
                    test: /\.(html)$/,
                    loader: 'html-normalize-loader'
                },
                { test: /\.scss$/, use: ExtractTextPlugin.extract(['css-loader?url=false', 'sass-loader?url=false']) },
            ]
        },
        resolve: {
            extensions: ['.js','.ts'],
            modules: [
                path.resolve(__dirname, 'node_modules'),
                path.resolve(__dirname, 'src'),
                path.resolve(__dirname, './client-app')
            ]
        },
        optimization: {
            minimize: !debug,
            noEmitOnErrors: true
        },
    };

    config.plugins = [
        new ExtractTextPlugin('app.bundle.css')
    ];

    return config;
};


