const { merge } = require("webpack-merge");
const webpack = require("webpack");
const { setupCommonConfig } = require("./common");
const commonServerConfig = require("./server");
const commonClientConfig = require("./client");

const clientConfig = merge(setupCommonConfig(true), commonClientConfig, {
    name: "client",
    mode: "development",
    entry: {
        public: ["webpack-hot-middleware/client?path=/__webpack_hmr", "./modules/client-framework/Entry.ts"],
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.DefinePlugin({
            IS_PRODUCTION: false,
            IS_SERVER_SIDE: false,
        }),
    ],
    devtool: "inline-source-map", // slowest build/slowest rebuild but shows proper source, eval-cheap-source-map is only like 2 seconds faster and gives us transpiled code
});

const clientShellConfig = merge(setupCommonConfig(true, undefined, "ES2017", false), commonClientConfig, {
    name: "client-shell",
    mode: "development",
    entry: {
        shell: ["webpack-hot-middleware/client?path=/__webpack_hmr", "./modules/shell/Entry.ts"],
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.DefinePlugin({
            IS_PRODUCTION: false,
            IS_SERVER_SIDE: false,
        }),
    ],
    devtool: "inline-source-map", // slowest build/slowest rebuild but shows proper source, eval-cheap-source-map is only like 2 seconds faster and gives us transpiled code
});

const serverConfig = merge(setupCommonConfig(true, undefined, "ES2022"), commonServerConfig, {
    name: "server",
    mode: "development",
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.DefinePlugin({
            IS_PRODUCTION: false,
            IS_SERVER_SIDE: true,
        }),
    ],
    devtool: "eval-cheap-source-map", // fast build/faster rebuild - line numbers slightly off because they are from transpiled source. inline-source-map wasn't working
});

module.exports = [clientConfig, clientShellConfig, serverConfig];
