From c5c821205b626a6f2d57550b1991ddafde4beb0f Mon Sep 17 00:00:00 2001 From: Jan Nicklas Date: Wed, 20 Jan 2021 16:25:44 +0100 Subject: [PATCH] feat: add meta attribute for html tags BREAKING CHANGE: Plugins adding additional assetTags should provide a meta attribute --- index.js | 5 +++++ lib/html-tags.js | 6 +++++- typings.d.ts | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 4f5ad856..bf11ee19 100644 --- a/index.js +++ b/index.js @@ -717,6 +717,7 @@ function hookIntoCompiler (compiler, options, plugin) { return jsAssets.map(scriptAsset => ({ tagName: 'script', voidTag: false, + meta: { plugin: 'html-webpack-plugin' }, attributes: { defer: options.scriptLoading !== 'blocking', src: scriptAsset @@ -733,6 +734,7 @@ function hookIntoCompiler (compiler, options, plugin) { return cssAssets.map(styleAsset => ({ tagName: 'link', voidTag: true, + meta: { plugin: 'html-webpack-plugin' }, attributes: { href: styleAsset, rel: 'stylesheet' @@ -755,6 +757,7 @@ function hookIntoCompiler (compiler, options, plugin) { return [{ tagName: 'base', voidTag: true, + meta: { plugin: 'html-webpack-plugin' }, attributes: (typeof baseOption === 'string') ? { href: baseOption } : baseOption @@ -797,6 +800,7 @@ function hookIntoCompiler (compiler, options, plugin) { return { tagName: 'meta', voidTag: true, + meta: { plugin: 'html-webpack-plugin' }, attributes: metaTagAttributes }; }); @@ -814,6 +818,7 @@ function hookIntoCompiler (compiler, options, plugin) { return [{ tagName: 'link', voidTag: true, + meta: { plugin: 'html-webpack-plugin' }, attributes: { rel: 'icon', href: faviconPath diff --git a/lib/html-tags.js b/lib/html-tags.js index 94911d1a..5e727a92 100644 --- a/lib/html-tags.js +++ b/lib/html-tags.js @@ -54,13 +54,17 @@ function htmlTagObjectToString (tagDefinition, xhtml) { * * @param {string} [innerHTML] * + * @param {{[attributeName: string]: string|boolean}} [meta] + * meta information about the tag e.g. `{ 'pluhin': 'html-webpack-plugin' }` + * * @returns {HtmlTagObject} */ -function createHtmlTagObject (tagName, attributes, innerHTML) { +function createHtmlTagObject (tagName, attributes, innerHTML, meta) { return { tagName: tagName, voidTag: voidTags.indexOf(tagName) !== -1, attributes: attributes || {}, + meta: meta || {}, innerHTML: innerHTML }; } diff --git a/typings.d.ts b/typings.d.ts index ecd3bb22..cbda83c8 100644 --- a/typings.d.ts +++ b/typings.d.ts @@ -278,5 +278,13 @@ declare namespace HtmlWebpackPlugin { * @see https://www.w3.org/TR/html5/syntax.html#void-elements */ voidTag: boolean; + /** + * Meta information about the tag + * E.g. `{'plugin': 'html-webpack-plugin'}` + */ + meta: { + plugin?: string, + [metaAttributeName: string]: any; + }; } }