Skip to content
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

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

Closed
foyzhao opened this issue Apr 2, 2020 · 10 comments · Fixed by #1802 · May be fixed by #1693
Closed

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

foyzhao opened this issue Apr 2, 2020 · 10 comments · Fixed by #1802 · May be fixed by #1693

Comments

@foyzhao
Copy link

foyzhao commented Apr 2, 2020

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>
@jantimon
Copy link
Owner

jantimon commented Apr 2, 2020

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

@foyzhao
Copy link
Author

foyzhao commented Apr 2, 2020

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.

@jantimon
Copy link
Owner

jantimon commented Apr 8, 2020

Yes that sounds just right

@stale stale bot added the wontfix label Oct 11, 2020
Repository owner deleted a comment from stale bot Oct 12, 2020
@stale stale bot removed the wontfix label Oct 12, 2020
@hectorgrebbell
Copy link

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

@jantimon
Copy link
Owner

jantimon commented Feb 3, 2021

Oh sorry I forgot about this one! 😱

@Den-dp
Copy link

Den-dp commented Sep 2, 2021

So the problem is here in userOptions.template check

// Default metaOptions if no template is provided
if (!userOptions.template && options.templateContent === false && options.meta) {
const defaultMeta = {
// From https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag
viewport: 'width=device-width, initial-scale=1'
};
options.meta = Object.assign({}, options.meta, defaultMeta, userOptions.meta);
}

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 added a commit to Den-dp/html-webpack-plugin that referenced this issue Oct 20, 2021
Take into account `src/index.ejs` existence while deciding to add default meta-tags.

Closes: jantimon#1387
@Den-dp
Copy link

Den-dp commented Oct 20, 2021

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

@stale
Copy link

stale bot commented Apr 18, 2022

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 stale bot added the wontfix label Apr 18, 2022
@scottohara
Copy link

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

@stale stale bot removed the wontfix label Apr 21, 2022
Den-dp added a commit to Den-dp/html-webpack-plugin that referenced this issue Jun 4, 2022
Take into account `src/index.ejs` existence while deciding to add default meta-tags.

Closes: jantimon#1387
@rafa852
Copy link

rafa852 commented Oct 8, 2022

<title>title</title>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants