Html-webpack-plugin: use contenthash instead of hash

Created on 27 Mar 2020  路  8Comments  路  Source: jantimon/html-webpack-plugin

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 [email protected] 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 [email protected] 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: [email protected] 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.

wontfix

Most helpful comment

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

All 8 comments

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

Filenames should not contain question marks.

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

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.

Same as:

1367

1346

1355

I have reported this issue here: https://github.com/webpack/webpack/issues/10638

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?

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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lonelydatum picture lonelydatum  路  3Comments

laruiss picture laruiss  路  3Comments

lcxfs1991 picture lcxfs1991  路  4Comments

var-bp picture var-bp  路  3Comments

Rowno picture Rowno  路  3Comments