html-webpack-plugin icon indicating copy to clipboard operation
html-webpack-plugin copied to clipboard

An extra ‘viewport’ meta with default template 'src/index.ejs'

Open foyzhao opened this issue 6 years ago • 10 comments

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>

foyzhao avatar Apr 02 '20 04:04 foyzhao

Oh you are right what would be the best solution for that?

jantimon avatar Apr 02 '20 07:04 jantimon

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.

foyzhao avatar Apr 02 '20 07:04 foyzhao

Yes that sounds just right

jantimon avatar Apr 08 '20 07:04 jantimon

Bumping as this is still an issue. Agree that this should offer the same behaviour as an explicitly provided user template.

hectorgrebbell avatar Jan 16 '21 14:01 hectorgrebbell

Oh sorry I forgot about this one! 😱

jantimon avatar Feb 03 '21 12:02 jantimon

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?

Den-dp avatar Sep 02 '21 17:09 Den-dp

Added the proposed (but slightly modified) solution as PR #1693

Den-dp avatar Oct 20 '21 13:10 Den-dp

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.

stale[bot] avatar Apr 18 '22 19:04 stale[bot]

Bump to avoid being auto-closed (issue is still unresolved as of v5.5.0)

scottohara avatar Apr 21 '22 01:04 scottohara

title

rafa852 avatar Oct 08 '22 07:10 rafa852