"use strict";
/*
 * Copyright 2018, collaboration Factory AG. All rights reserved.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.CReplacePlugin = void 0;
const utils_1 = require("../model/utils");
class CReplacePlugin {
    constructor() { }
    apply(compiler) {
        compiler.hooks.compilation.tap('CPlaceResolverPlugin', (compilation) => {
            compilation.hooks.dependencyReference.tap('CPlaceResolverPlugin', (_, { module }) => {
                const { externalType, userRequest } = module;
                if (utils_1.isFromLibrary(userRequest)) {
                    const moduleReplacement = userRequest.replace(/(^@)([a-zA-Z0-9.]+)(\/.+)/gi, (match, _, folder, path) => {
                        const resolver = folder.replace(/\./g, '_');
                        const module = `.${path}.js`;
                        return `window['$${resolver}']('${module}')`;
                    });
                    module.externalType = '';
                    module.request = moduleReplacement;
                }
            });
        });
    }
}
exports.CReplacePlugin = CReplacePlugin;
//# sourceMappingURL=CReplacePlugin.js.map