New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add meta
option
#419
Add meta
option
#419
Conversation
could this also be a key value pair? |
A single |
I was just thinking because we could set meaningful defaults if it would be named... but right now I don't have a good idea for that.. Maybe we can come up with something - otherwise I will merge this one |
Here is a list of all possible header values: |
What about:
to get
That way we could come up with a good default and a user might then just unset a value e.g. |
How would you infer |
I'm with you on making it easy to add these (I think this should perhaps remove the ones from the default template, and add them through this API), but the current approach represents a simpler implementation to understand and maintain. |
Yes the api is kind of ugly ;) And yes we should replace the default template attributes. According to the list https://github.com/joshbuchea/HEAD#meta every setting is placed into content.
And if it is not content we would still have the opportunity to set it with an object instead of a string |
So the key could ble split on colon, and the value could be placed in |
So you want new HtmlWebpackPlugin({ meta: { 'charset:utf-8': null, 'http-equiv:x-ua-compatible': 'ie=edge' } }) ? |
Yes I guess that would be nice - maybe we use
what do you think? |
@jantimon Updated now. Not sure how to force it at the top of |
Hmm this is quite nice and you are right we should probably push it to the beginning of head. |
We could drop changing the default template here, and release that as a separate thing (keep a PR open with the change until you're ready to release a v3 |
Maybe we should just not use defaults and go with your initial proposal. |
Hmm but then the base template would be mixed |
What do you want me to do? Drop the last commit? Or just the defaults in it? |
Hmm I really like the idea but I would like to try a different approach let me prepare a draft |
Okay sorry seems to take longer than I hoped because of webpack/webpack#2978 |
Any status on this ? |
Since v3 is coming, maybe merge this as is? I haven't touched it since the discussions happened |
FWIW, I still prefer the original API, with an array of objects. Clean and easy, no inferrence or magic delimiters |
You are right - magic is almost every time a bad idea. What about a mix of both of the ideas so we get defaults, an easy configuration for name:content pairs and full power if needed:
|
Why not just simply a [Template] String ? // {String}
new HTMLPlugin({
meta: `
<meta charset="utf8">
<meta ...>
`
})
// {Function}
new HTMLPlugin({
meta: (ctx) => `
<meta charset=${ctx.charset}>
<meta ...>
<meta ...>
`
}) |
Sorry for postponing the topic for so long. What about the following structure: {
charset: { 'charset': 'utf-8' },
viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no',
'Content-Security-Policy': { 'content': 'default-src "self"', 'http-equiv': 'Content-Security-Policy'},
} This would allow a very extensible api with defaults. {
charset: { 'charset': 'utf-8' },
viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'
} And could easily be overwritten e.g. new HtmlWebpackPlugin({
meta: {
viewport: false,
// or
viewport: width=500, initial-scale=1
},
} And the default could easily be extended: new HtmlWebpackPlugin({
meta: {
referrer: 'no-referrer'
},
} The following function would convert it internally into the structure you proposed initally: function getMetaTagArray(meta) {
if (meta === false) {
return [];
}
const metaObjects = Object.entries(meta).map(([metaName, value]) => {
return (typeof value === 'object') ? value : {
name: metaName,
content: value
};
});
return metaObjects;
} |
Hah, completely forgot about this. 😀 How would you do meta tags without |
@SimenB haha me too 😉 Just like the {
'og:image:width' : {
property: 'og:image:width',
content: 1200
}
} I created an interactive example to play around: |
Ah, so if the value is an object, that's used as is, but if the value is a string, its key becomes |
What about having an array directly: less moving parts, easier for the user to understand
A bit longer tough. EDIT: Just realised, I was reiterating something that was already proposed earlier... -_- |
Yeah, that's the API of my original commit if you look at the history. 🙂 FWIW I still think that'd be the cleanest solution, but I have nothing in particular against @jantimon's latest suggestion either |
I totally agree that the array looks easier but it’s harder to modify as it it number based. |
Moved to #906. |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Only reason I still keep around a custom template