Skip to content

Commit

Permalink
fix: rename contenthash to templatehash
Browse files Browse the repository at this point in the history
BREAKING: `contenthash` in now `templatehash`. Since webpack 4.3 `contenthash` is used by webpack. to avoid conflicts, it is renamed to `templatehash`
  • Loading branch information
sibiraj-s authored and jantimon committed Oct 2, 2018
1 parent 79a0448 commit 4c11c5d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -279,10 +279,10 @@ class HtmlWebpackPlugin {
return self.options.showErrors ? prettyError(err, compiler.context).toHtml() : 'ERROR';
})
.then(html => {
// Allow to use [contenthash] as placeholder for the html-webpack-plugin name
// Allow to use [templatehash] as placeholder for the html-webpack-plugin name
// See also https://survivejs.com/webpack/optimizing/adding-hashes-to-filenames/
// From https://github.com/webpack-contrib/extract-text-webpack-plugin/blob/8de6558e33487e7606e7cd7cb2adc2cccafef272/src/index.js#L212-L214
const finalOutputName = childCompilationOutputName.replace(/\[(?:(\w+):)?contenthash(?::([a-z]+\d*))?(?::(\d+))?\]/ig, (_, hashType, digestType, maxLength) => {
const finalOutputName = childCompilationOutputName.replace(/\[(?:(\w+):)?templatehash(?::([a-z]+\d*))?(?::(\d+))?\]/ig, (_, hashType, digestType, maxLength) => {
return loaderUtils.getHashDigest(Buffer.from(html, 'utf8'), hashType, digestType, parseInt(maxLength, 10));
});
// Add the evaluated html code to the webpack assets
Expand Down
4 changes: 2 additions & 2 deletions spec/basic.spec.js
Expand Up @@ -626,7 +626,7 @@ describe('HtmlWebpackPlugin', () => {
}, ['<script src="index_bundle.js"'], /test-\S+\.html$/, done);
});

it('will replace [contenthash] in the filename with a content hash of 32 hex characters', done => {
it('will replace [templatehash] in the filename with a content hash of 32 hex characters', done => {
testHtmlPlugin({
mode: 'production',
entry: {
Expand All @@ -637,7 +637,7 @@ describe('HtmlWebpackPlugin', () => {
filename: '[name]_bundle.js'
},
plugins: [
new HtmlWebpackPlugin({filename: 'index.[contenthash].html'})
new HtmlWebpackPlugin({filename: 'index.[templatehash].html'})
]
}, [], /index\.[a-f0-9]{32}\.html/, done);
});
Expand Down

0 comments on commit 4c11c5d

Please sign in to comment.