"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getWebConfig = void 0;
const webpack_plugin_1 = __importDefault(require("@loadable/webpack-plugin"));
const terser_webpack_plugin_1 = __importDefault(require("terser-webpack-plugin"));
const webpack_blocks_1 = require("webpack-blocks");
const micro_core_1 = require("@vtex/micro-core");
const alias_1 = require("../alias");
const web_1 = require("./babel/web");
const web_legacy_1 = require("./babel/web-legacy");
exports.getWebConfig = async (_project, target) => {
    return [
        micro_core_1.alias(alias_1.aliases, module),
        webpack_blocks_1.addPlugins([
            new webpack_plugin_1.default({
                outputAsset: false,
                writeToDisk: false,
            }),
        ]),
        micro_core_1.cacheGroup(micro_core_1.pagesRuntimeName, /\/react\/|\/react-dom\/|\/@loadable\//),
        micro_core_1.cacheGroup(micro_core_1.pagesFrameworkName, /\/micro-plugin-*/),
        webpack_blocks_1.optimization({
            splitChunks: {
                maxInitialRequests: 30,
                maxAsyncRequests: 10,
            },
        }),
        webpack_blocks_1.env('production', [
            webpack_blocks_1.optimization({
                noEmitOnErrors: true,
                moduleIds: 'size',
                chunkIds: 'total-size',
                nodeEnv: 'production',
                removeAvailableModules: true,
                removeEmptyChunks: true,
                mergeDuplicateChunks: true,
                flagIncludedChunks: true,
                providedExports: true,
                usedExports: true,
                concatenateModules: true,
                sideEffects: true,
                portableRecords: false,
                minimizer: [
                    new terser_webpack_plugin_1.default({
                        extractComments: true,
                    }),
                ],
            }),
        ]),
        webpack_blocks_1.match(['*.tsx', '*.ts'], [target === 'web' ? web_1.babelConfig : web_legacy_1.babelConfig]),
    ];
};
