Skip to content

Commit

Permalink
feat: add meta attribute for html tags
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Plugins adding additional assetTags should provide a meta attribute
  • Loading branch information
jantimon committed Feb 3, 2021
1 parent d0ab774 commit c5c8212
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -797,6 +800,7 @@ function hookIntoCompiler (compiler, options, plugin) {
return {
tagName: 'meta',
voidTag: true,
meta: { plugin: 'html-webpack-plugin' },
attributes: metaTagAttributes
};
});
Expand All @@ -814,6 +818,7 @@ function hookIntoCompiler (compiler, options, plugin) {
return [{
tagName: 'link',
voidTag: true,
meta: { plugin: 'html-webpack-plugin' },
attributes: {
rel: 'icon',
href: faviconPath
Expand Down
6 changes: 5 additions & 1 deletion lib/html-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
Expand Down
8 changes: 8 additions & 0 deletions typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
}

0 comments on commit c5c8212

Please sign in to comment.