diff --git a/index.js b/index.js index d96988bc..b040cccd 100644 --- a/index.js +++ b/index.js @@ -99,6 +99,13 @@ class HtmlWebpackPlugin { this.options.filename = path.relative(compiler.options.output.path, filename); } + // `contenthash` is introduced in webpack v4.3 + // which conflicts with the plugin's existing `contenthash` method, + // hence it is renamed to `templatehash` to avoid conflicts + this.options.filename = this.options.filename.replace(/\[(?:(\w+):)?contenthash(?::([a-z]+\d*))?(?::(\d+))?\]/ig, (match) => { + return match.replace('contenthash', 'templatehash'); + }); + // Check if webpack is running in production mode // @see https://github.com/webpack/webpack/blob/3366421f1784c449f415cda5930a8e445086f688/lib/WebpackOptionsDefaulter.js#L12-L14 const isProductionLikeMode = compiler.options.mode === 'production' || !compiler.options.mode; diff --git a/spec/basic.spec.js b/spec/basic.spec.js index 17df8a6b..0cbde114 100644 --- a/spec/basic.spec.js +++ b/spec/basic.spec.js @@ -626,6 +626,38 @@ describe('HtmlWebpackPlugin', () => { }, ['