"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNodeConfig = 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 web_1 = require("../utils/babel/web");
exports.getNodeConfig = async (project, target) => {
    const externals = project.root.manifest.name === '@vtex/micro-plugin-react' &&
        target === 'render'
        ? {}
        : {
            react: 'React',
            'react-dom': 'ReactDOM',
            '@loadable/component': 'LoadableComponent',
        };
    return [
        // TODO: Externals should respect at least the semver
        webpack_blocks_1.customConfig({
            externals,
        }),
        webpack_blocks_1.addPlugins([
            new webpack_plugin_1.default({
                outputAsset: false,
                writeToDisk: false,
            }),
        ]),
        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'], [web_1.babelConfig]),
    ];
};
