"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HtmlFaviconUrlPlugin = void 0;
class HtmlFaviconUrlPlugin {
    constructor(options) {
        this.name = 'HtmlFaviconUrlPlugin';
        this.faviconUrls = options.faviconUrls;
        this.HtmlPlugin = options.HtmlPlugin;
    }
    apply(compiler) {
        // add html asset tags
        compiler.hooks.compilation.tap(this.name, (compilation) => {
            this.HtmlPlugin.getHooks(compilation).alterAssetTagGroups.tap(this.name, data => {
                const matched = this.faviconUrls.find(item => item.filename === data.outputName);
                if (matched) {
                    data.headTags.unshift({
                        tagName: 'link',
                        voidTag: true,
                        attributes: {
                            rel: 'icon',
                            href: matched.url,
                        },
                        meta: {},
                    });
                }
                return data;
            });
        });
    }
}
exports.HtmlFaviconUrlPlugin = HtmlFaviconUrlPlugin;
