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

use contenthash instead of hash #1374

Closed
foyzhao opened this issue Mar 27, 2020 · 8 comments
Closed

use contenthash instead of hash #1374

foyzhao opened this issue Mar 27, 2020 · 8 comments
Labels

Comments

@foyzhao
Copy link

foyzhao commented Mar 27, 2020

I want to insert a content hash instead of hash AFTER '?'

<link href="main.css?[contenthash but not hash]" rel="stylesheet">
<script src="main.js?[contenthash but not hash]"></script>

Maybe config like this:

new HtmlWebpackPlugin({
    // hash: true,
    hash: 'contenthash',
}),

Because...
I used to append a content hash like this:

module.exports = {
  ...
  entry: './src',
  output: {
    filename: '[name].js?[contenthash]',
  },
  ...
}

with html-webpack-plugin@3.2.0 it works fine

<html>
  <head>
    <meta charset="UTF-8">
    <title>Webpack App</title>
  </head>
  <body>
  <script src="main.js?803bc3411f4f1d2447c9"></script>
  </body>
</html>

but with html-webpack-plugin@4.0.2 it inject nothing into body

<html>
<head>
  <meta charset="utf-8">
  <title>Webpack App</title>
  <meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body></body>
</html>

Remark: html-webpack-plugin@4.0.2 could work when config like this

module.exports = {
  ...
  entry: './src',
  output: {
    filename: '[name].[contenthash].js',
  },
  ...
}
<html>
  <head>
    <meta charset="UTF-8">
    <title>Webpack App</title>
  </head>
  <body>
  <script src="main.803bc3411f4f1d2447c9.js"></script>
  </body>
</html>

But this is not what I want.

@zamanruhy
Copy link

Why filename: '[name].js?[contenthash]' is not work for inject now? Will it be fixed?

@jantimon
Copy link
Owner

Filenames should not contain question marks.

You could try [name].[hash].js

@foyzhao
Copy link
Author

foyzhao commented Mar 30, 2020

Filenames should not contain question marks.

You could try [name].[hash].js

I prefer to put the hash in the query string rather than the filename.

@jantimon
Copy link
Owner

Same as:

#1367
#1346
#1355

@jantimon
Copy link
Owner

I have reported this issue here: webpack/webpack#10638

@foyzhao
Copy link
Author

foyzhao commented Mar 30, 2020

I don't want to put a question mark in filename either, so I want to know if there is a way to replace the hash with contenthash, as mentioned at the beginning of this issue, something like add an option to the hash attribute.
hash: {Boolean|String}
Can it be implemented as a feature in the next release?

@jantimon
Copy link
Owner

I will try to bring back the same behaviour as in 3.2 for details please see #1355

@stale
Copy link

stale bot commented Oct 4, 2020

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 Oct 4, 2020
@stale stale bot closed this as completed Oct 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants