html-tag-attributes-plugin
v0.1.6
Published
Add custom attributes to tags injected by html-webpack-plugin
Downloads
8
Maintainers
Readme
html-tag-attributes-plugin
Add custom attributes to tags injected by html-webpack-plugin.
Requirements
set after html-webpack-plugin
Installation
$ npm i -D html-tag-attributes-plugin
Usage
{
plugins: [
new HtmlWebpackPlugin({
chunks: ['app', 'vendors']
}),
new HtmlTagAttributesPlugin({
script: {
crossorigin: 'anonymous',
async: true
},
link(tag) {
if (/app/.test(tag.attributes.src)) {
return {
crossorigin: 'anonymous'
};
}
},
meta: {
'data-test': 'test'
}
})
]
}
output
<script src="app.ad38234f.js" crossorigin="anonymous" async></script>
<link rel="stylesheet" type="text/css" href="app.be372c5a.css" crossorigin="anonymous">
<meta data-test="test" />
Options
<tagName>
(Object
orFunction
),<tagName>
can bescript
,link
ormeta
, all tagNames ofHtmlTagObject
are supported, see html-webpack-plugin- If
<tagName>
is anObject
, all own properties of<tagName>
will treat as html attributes. - If
<tagname>
is aFunction
, whose arguments is aHtmlTagObject
, must return aObject
as html attributes.