const path = require('path');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');

module.exports = {
    entry:  {
        app: './src/index.js',
        // 'editor.worker': 'monaco-editor/esm/vs/editor/editor.worker.js',
        // 'json.worker': 'monaco-editor/esm/vs/language/json/json.worker',
        // 'css.worker': 'monaco-editor/esm/vs/language/css/css.worker',
        // 'html.worker': 'monaco-editor/esm/vs/language/html/html.worker',
        // 'ts.worker': 'monaco-editor/esm/vs/language/typescript/ts.worker'
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-env']
                    }
                }
            },
            {
                test: /\.less$/,
                use: [
                    'style-loader', // Creates `style` nodes from JS strings
                    'css-loader',   // Translates CSS into CommonJS
                    'less-loader'   // Compiles Less to CSS
                ]
            },
            {
                test: /\.css$/,
                use: ['style-loader', 'css-loader']
            },
            {
                test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
                use: [
                    {
                        loader: 'file-loader',
                        options: {
                            name: '[name].[ext]',
                            outputPath: 'fonts/',
                        },
                    },
                ],
            }
        ]
    },
    plugins: [new MonacoWebpackPlugin()],
    externals: {
        jquery: 'jQuery',
        bootstrap: 'bootstrap',
        lodash: '_',
        monaco : 'monaco'
    },
    output: {
        library: {
            name: 'APITestManager',
            type: 'umd',
            export: 'default'
        },
        globalObject: `(typeof self !== 'undefined' ? self : this)`,
        // globalObject: 'self',
        path: path.resolve(__dirname, 'dist'),
        filename: '[name].bundle.js',
    },
    mode: 'development',
    devServer: {
        proxy : {
            '/mgmt': {
                target: 'http://localhost:38080',
                changeOrigin: true,
            }
        }
    },
    // optimization: {
    //     splitChunks: {
    //         chunks: 'all',
    //         automaticNameDelimiter: '-',
    //         cacheGroups: {
    //             vendor: {
    //                 test: /[\\/]node_modules[\\/]/,
    //                 name: 'vendors',
    //                 chunks: 'all',
    //             }
    //         }
    //     }
    // }
};
