"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HtmlCrossOriginPlugin = void 0;
class HtmlCrossOriginPlugin {
    constructor(options) {
        const { crossOrigin } = options;
        this.name = 'HtmlCrossOriginPlugin';
        this.crossOrigin = crossOrigin;
        this.HtmlPlugin = options.HtmlPlugin;
    }
    apply(compiler) {
        if (!this.crossOrigin) {
            return;
        }
        compiler.hooks.compilation.tap(this.name, compilation => {
            this.HtmlPlugin.getHooks(compilation).alterAssetTags.tapPromise(this.name, async (alterAssetTags) => {
                const { assetTags: { scripts, styles }, } = alterAssetTags;
                scripts.forEach(script => (script.attributes.crossorigin = this.crossOrigin));
                styles.forEach(style => (style.attributes.crossorigin = this.crossOrigin));
                return alterAssetTags;
            });
        });
    }
}
exports.HtmlCrossOriginPlugin = HtmlCrossOriginPlugin;
