@@ -83,11 +83,12 @@ class HtmlWebpackPlugin {
83
83
options . meta = Object . assign ( { } , options . meta , defaultMeta , userOptions . meta ) ;
84
84
}
85
85
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
89
90
// 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 ) ;
91
92
92
93
/** output filenames for the given entry names */
93
94
const outputFileNames = new Set ( Object . keys ( compiler . options . entry ) . map ( filenameFunction ) ) ;
@@ -153,6 +154,12 @@ function hookIntoCompiler (compiler, options, plugin) {
153
154
// Instance variables to keep caching information
154
155
// for multiple builds
155
156
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 = [ ] ;
156
163
157
164
options . template = getFullTemplatePath ( options . template , compiler . context ) ;
158
165
@@ -245,8 +252,12 @@ function hookIntoCompiler (compiler, options, plugin) {
245
252
// If the template and the assets did not change we don't have to emit the html
246
253
const newAssetJson = JSON . stringify ( getAssetFiles ( assets ) ) ;
247
254
if ( isCompilationCached && options . cache && assetJson === newAssetJson ) {
255
+ previousEmittedAssets . forEach ( ( { name, html } ) => {
256
+ compilation . emitAsset ( name , new webpack . sources . RawSource ( html , false ) ) ;
257
+ } ) ;
248
258
return callback ( ) ;
249
259
} else {
260
+ previousEmittedAssets = [ ] ;
250
261
assetJson = newAssetJson ;
251
262
}
252
263
@@ -349,6 +360,7 @@ function hookIntoCompiler (compiler, options, plugin) {
349
360
} ) ;
350
361
// Add the evaluated html code to the webpack assets
351
362
compilation . emitAsset ( finalOutputName , new webpack . sources . RawSource ( html , false ) ) ;
363
+ previousEmittedAssets . push ( { name : finalOutputName , html } ) ;
352
364
return finalOutputName ;
353
365
} )
354
366
. then ( ( finalOutputName ) => getHtmlWebpackPluginHooks ( compilation ) . afterEmit . promise ( {
0 commit comments