"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const cli_core_1 = require("@bluebase/cli-core");
const webpack_merge_1 = __importDefault(require("webpack-merge"));
const useOwn_1 = __importDefault(require("../../scripts/useOwn"));
// tslint:disable-next-line:no-var-requires
const HappyPack = require('happypack');
const removeNil = cli_core_1.Utils.removeNil;
/**
 * Javascript loader
 * @param config
 * @param builder
 */
const LoaderJavascript = () => (config, builder) => {
    const newConfig = webpack_merge_1.default(config, {
        plugins: removeNil([
            // HappyPack 'javascript' instance.
            new HappyPack({
                id: 'happypack-javascript',
                verbose: false,
                // tslint:disable-next-line:object-literal-sort-keys
                threads: 4,
                loaders: [
                    {
                        // We will use babel to do all our JS processing.
                        path: useOwn_1.default('babel-loader'),
                        // We will create a babel config and pass it through the plugin
                        // defined in the project configuration, allowing additional
                        // items to be added.
                        query: 
                        // Our "standard" babel config.
                        {
                            // We need to ensure that we do this otherwise the babelrc will
                            // get interpretted and for the current configuration this will mean
                            // that it will kill our webpack treeshaking feature as the modules
                            // transpilation has not been disabled within in.
                            babelrc: false,
                            plugins: [
                                // Required to support react hot loader.
                                builder.ifDevClient(useOwn_1.default('react-hot-loader/babel')),
                            ].filter(x => x != null),
                        },
                    },
                ],
            }),
        ]),
    });
    newConfig.module.rules[0].oneOf = [
        // JAVASCRIPT
        {
            test: /\.jsx?$/,
            // We will defer all our js processing to the happypack plugin
            // named "happypack-javascript".
            // See the respective plugin within the plugins section for full
            // details on what loader is being implemented.
            loader: useOwn_1.default('happypack/loader?id=happypack-javascript'),
            include: removeNil([
                ...builder.configs.includePaths,
            ]),
        },
    ].concat(newConfig.module.rules[0].oneOf);
    return newConfig;
};
exports.default = LoaderJavascript;
//# sourceMappingURL=LoaderJavascript.js.map