An extra ‘viewport’ meta with default template 'src/index.ejs'
I have an html template file src/index.ejs and the viewport meta has been defined.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,viewport-fit=cover">
<title>title</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
When I don't configure the template option (the documentation says that src/index.ejs will be used by default)
plugins: [
...
new HtmlWebpackPlugin(),
],
Another viewport meta is generated.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,viewport-fit=cover">
<title>title</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="/main.css?d892d63a" rel="stylesheet">
</head>
<body>
<div id="root"></div>
<script src="/main.js?a6a01c58"></script>
</body>
</html>
But if I specify src/index.ejs as the template
plugins: [
...
new HtmlWebpackPlugin(
template: 'src/index.ejs',
),
],
The result is what I expected.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,viewport-fit=cover">
<title>title</title>
<link href="/main.css?d892d63a" rel="stylesheet">
</head>
<body>
<div id="root"></div>
<script src="/main.js?a6a01c58"></script>
</body>
</html>
Oh you are right what would be the best solution for that?
First of all, I think the result should be exactly the same whether you explicitly specify template as src/index.ejs or implicitly use src/index.ejs as fallback when no template is configured.
Yes that sounds just right
Bumping as this is still an issue. Agree that this should offer the same behaviour as an explicitly provided user template.
Oh sorry I forgot about this one! 😱
So the problem is here in userOptions.template check
https://github.com/jantimon/html-webpack-plugin/blob/2f5de7ab9e8bca60e9e200f2e4b4cfab90db28d4/index.js#L76-L83
The simplest (but pretty dirty) solution would be to check for the existence of a file:
if (!userOptions.template && !fs.existsSync('./src/index.ejs') && options.templateContent === false && options.meta) {
@jantimon Any other ideas?
Added the proposed (but slightly modified) solution as PR #1693
This issue had no activity for at least half a year. It's subject to automatic issue closing if there is no activity in the next 15 days.
Bump to avoid being auto-closed (issue is still unresolved as of v5.5.0)