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