Skip to content

Commit c5c8212

Browse files
committed
feat: add meta attribute for html tags
BREAKING CHANGE: Plugins adding additional assetTags should provide a meta attribute
1 parent d0ab774 commit c5c8212

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

index.js

+5
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ function hookIntoCompiler (compiler, options, plugin) {
717717
return jsAssets.map(scriptAsset => ({
718718
tagName: 'script',
719719
voidTag: false,
720+
meta: { plugin: 'html-webpack-plugin' },
720721
attributes: {
721722
defer: options.scriptLoading !== 'blocking',
722723
src: scriptAsset
@@ -733,6 +734,7 @@ function hookIntoCompiler (compiler, options, plugin) {
733734
return cssAssets.map(styleAsset => ({
734735
tagName: 'link',
735736
voidTag: true,
737+
meta: { plugin: 'html-webpack-plugin' },
736738
attributes: {
737739
href: styleAsset,
738740
rel: 'stylesheet'
@@ -755,6 +757,7 @@ function hookIntoCompiler (compiler, options, plugin) {
755757
return [{
756758
tagName: 'base',
757759
voidTag: true,
760+
meta: { plugin: 'html-webpack-plugin' },
758761
attributes: (typeof baseOption === 'string') ? {
759762
href: baseOption
760763
} : baseOption
@@ -797,6 +800,7 @@ function hookIntoCompiler (compiler, options, plugin) {
797800
return {
798801
tagName: 'meta',
799802
voidTag: true,
803+
meta: { plugin: 'html-webpack-plugin' },
800804
attributes: metaTagAttributes
801805
};
802806
});
@@ -814,6 +818,7 @@ function hookIntoCompiler (compiler, options, plugin) {
814818
return [{
815819
tagName: 'link',
816820
voidTag: true,
821+
meta: { plugin: 'html-webpack-plugin' },
817822
attributes: {
818823
rel: 'icon',
819824
href: faviconPath

lib/html-tags.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,17 @@ function htmlTagObjectToString (tagDefinition, xhtml) {
5454
*
5555
* @param {string} [innerHTML]
5656
*
57+
* @param {{[attributeName: string]: string|boolean}} [meta]
58+
* meta information about the tag e.g. `{ 'pluhin': 'html-webpack-plugin' }`
59+
*
5760
* @returns {HtmlTagObject}
5861
*/
59-
function createHtmlTagObject (tagName, attributes, innerHTML) {
62+
function createHtmlTagObject (tagName, attributes, innerHTML, meta) {
6063
return {
6164
tagName: tagName,
6265
voidTag: voidTags.indexOf(tagName) !== -1,
6366
attributes: attributes || {},
67+
meta: meta || {},
6468
innerHTML: innerHTML
6569
};
6670
}

typings.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -278,5 +278,13 @@ declare namespace HtmlWebpackPlugin {
278278
* @see https://www.w3.org/TR/html5/syntax.html#void-elements
279279
*/
280280
voidTag: boolean;
281+
/**
282+
* Meta information about the tag
283+
* E.g. `{'plugin': 'html-webpack-plugin'}`
284+
*/
285+
meta: {
286+
plugin?: string,
287+
[metaAttributeName: string]: any;
288+
};
281289
}
282290
}

0 commit comments

Comments
 (0)