"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const webpack_1 = require("webpack");
const cli_core_1 = require("@bluebase/cli-core");
const webpack_merge_1 = __importDefault(require("webpack-merge"));
const ifElse = cli_core_1.Utils.ifElse;
const removeNil = cli_core_1.Utils.removeNil;
/**
 * Add source map support
 * @param config
 * @param builder
 */
const SourceMaps = () => (config, builder) => {
    return webpack_merge_1.default(config, {
        // Source map settings.
        devtool: ifElse(
        // Include source maps for ANY node bundle so that we can support
        // nice stack traces for errors (the source maps get consumed by
        // the `node-source-map-support` module to allow for this).
        builder.isNode ||
            // Always include source maps for any development build.
            builder.isDev ||
            // Allow for the following flag to force source maps even for production
            // builds.
            builder.configs.includeSourceMapsForOptimisedClientBundle)(
        // Produces an external source map (lives next to bundle output files).
        'source-map', 
        // Produces no source map.
        'hidden-source-map'),
        plugins: removeNil([
            // This grants us source map support, which combined with our webpack
            // source maps will give us nice stack traces for our node executed
            // bundles.
            // We use the BannerPlugin to make sure all of our chunks will get the
            // source maps support installed.
            builder.ifNode(() => new webpack_1.BannerPlugin({
                banner: 'require("source-map-support").install();',
                entryOnly: false,
                raw: true,
            })),
        ]),
    });
};
exports.default = SourceMaps;
//# sourceMappingURL=SourceMaps.js.map