Closed tkrotoff closed 5 years ago
Interesting idea but this plugin uses html-webpack-plugin
to insert the tags and it only currently supports link
or script
tags.
It might be better to open this issue on that plugin first...
Are you sure html-webpack-plugin
does not handle <meta>
?
The alterAssetTags
hook takes meta: Array<HtmlTagObject>
Ok, html-webpack-plugin
does support meta tags, but only through options.meta
, which you can see here
Basically, if you want to inject meta
tags, you need to do so through the html-webpack-plugin
options, something like:
plugins: [
new HtmlWebpackPlugin({ meta: { "msapplication-config": { name: "msapplication-config", content: "favicons/browserconfig.xml" }),
new HtmlWebpackTagsPlugin({ scripts: [], links: [] })
]
Can you give the above a try, and let me know if it works? ;-)
If I use HtmlWebpackPlugin instead of HtmlWebpackTagsPlugin, file browserconfig.xml
won't be hashed (it's then better to directly hardcode <meta name="msapplication-config" content="favicons/browserconfig.xml" />
inside index.html).
The use case is to have all favicons files to be hashed, something like <meta name="msapplication-config" content="favicons/browserconfig.xml?8f58478fb4d4d32bcacf" />
.
Of course there is no hash (and thus no need to use HtmlWebpackTagsPlugin) for:
<meta name="msapplication-TileColor" content="#da532c" />
<meta name="theme-color" content="#ffffff" />
Ok, I can see that being able to inject the publicPath
or hash
into the meta tag content
attribute could be useful, so I've added a new option to allow that in version 2.0.14
, along with several (passing) tests.
@tkrotoff Can you please try out the new option and let me know if it works for you? If so we can close this issue... ;-)
I've added the following example to the README. The example uses the publicPath
, but works for hash
as well.
Using the meta
option to inject meta
tags:
output: {
publicPath: '/my-public-path/'
},
plugins: [
new CopyWebpackPlugin([
{ from: 'node_modules/bootstrap/dist/js', to: 'js/'}
]),
new HtmlWebpackPlugin(),
new HtmlWebpackTagsPlugin({
meta: [
{
path: 'asset/path',
attributes: {
name: 'the-meta-name'
}
}
]
})
]
Will inject the following <meta>
element into the index template html
<head>
<!-- previous header content -->
<meta content="/my-public-path/asset/path" name="the-meta-name">
</head>
Note that the append
settings has no effect on how the <meta>
elements are injected.
Works great, thx!
However, the name meta
feels wrong since there is scripts
and links
(and all of them take an array). I would have go for metas
plural form.
I agree, but since this is really just using the html-webpack-plugin
meta
option under the covers, I decided to keep them the same.
just using the
html-webpack-plugin
meta
option under the covers
IMHO this is an implementation detail that users don't care about, they much prefer consistent APIs.
Anyway, it works wonderfully. Thanks a lot :-)
@tkrotoff after reflection I think you are correct that metas
is a more consistent option name than meta
.
I renamed it in version 2.0.15
, shouldn't be a breaking change as nobody is using it yet.
:-)
Currently html-webpack-tags-plugin supports
<link>
and<script>
, but it does not support<meta>
.Use case:
<meta name="msapplication-config" content="favicons/browserconfig.xml?8f58478fb4d4d32bcacf" />
, see https://realfavicongenerator.net/Full use case, add favicons to index.html and hash the filenames, example: