@@ -83,11 +83,12 @@ class HtmlWebpackPlugin {
8383 options . meta = Object . assign ( { } , options . meta , defaultMeta , userOptions . meta ) ;
8484 }
8585
86- // entryName to fileName conversion
87- const filenameFunction = typeof options . filename === 'function'
88- ? options . filename
86+ // entryName to fileName conversion function
87+ const userOptionFilename = userOptions . filename || defaultOptions . filename ;
88+ const filenameFunction = typeof userOptionFilename === 'function'
89+ ? userOptionFilename
8990 // Replace '[name]' with entry name
90- : ( entryName ) => options . filename . replace ( / \[ n a m e \] / g, entryName ) ;
91+ : ( entryName ) => userOptionFilename . replace ( / \[ n a m e \] / g, entryName ) ;
9192
9293 /** output filenames for the given entry names */
9394 const outputFileNames = new Set ( Object . keys ( compiler . options . entry ) . map ( filenameFunction ) ) ;
@@ -153,6 +154,12 @@ function hookIntoCompiler (compiler, options, plugin) {
153154 // Instance variables to keep caching information
154155 // for multiple builds
155156 let assetJson ;
157+ /**
158+ * store the previous generated asset to emit them even if the content did not change
159+ * to support watch mode for third party plugins like the clean-webpack-plugin or the compression plugin
160+ * @type {Array<{html: string, name: string}> }
161+ */
162+ let previousEmittedAssets = [ ] ;
156163
157164 options . template = getFullTemplatePath ( options . template , compiler . context ) ;
158165
@@ -245,8 +252,12 @@ function hookIntoCompiler (compiler, options, plugin) {
245252 // If the template and the assets did not change we don't have to emit the html
246253 const newAssetJson = JSON . stringify ( getAssetFiles ( assets ) ) ;
247254 if ( isCompilationCached && options . cache && assetJson === newAssetJson ) {
255+ previousEmittedAssets . forEach ( ( { name, html } ) => {
256+ compilation . emitAsset ( name , new webpack . sources . RawSource ( html , false ) ) ;
257+ } ) ;
248258 return callback ( ) ;
249259 } else {
260+ previousEmittedAssets = [ ] ;
250261 assetJson = newAssetJson ;
251262 }
252263
@@ -349,6 +360,7 @@ function hookIntoCompiler (compiler, options, plugin) {
349360 } ) ;
350361 // Add the evaluated html code to the webpack assets
351362 compilation . emitAsset ( finalOutputName , new webpack . sources . RawSource ( html , false ) ) ;
363+ previousEmittedAssets . push ( { name : finalOutputName , html } ) ;
352364 return finalOutputName ;
353365 } )
354366 . then ( ( finalOutputName ) => getHtmlWebpackPluginHooks ( compilation ) . afterEmit . promise ( {
0 commit comments