@@ -336,17 +336,20 @@ class HtmlWebpackPlugin {
336
336
headTags: HtmlTagObject[],
337
337
bodyTags: HtmlTagObject[]
338
338
}} assetTags
339
- * @returns {{[key: any]: any} }
339
+ * @returns {Promise< {[key: any]: any}> }
340
340
*/
341
341
getTemplateParameters ( compilation , assets , assetTags ) {
342
- if ( this . options . templateParameters === false ) {
343
- return { } ;
342
+ const templateParameters = this . options . templateParameters ;
343
+ if ( templateParameters === false ) {
344
+ return Promise . resolve ( { } ) ;
344
345
}
345
- if ( typeof this . options . templateParameters === 'function' ) {
346
- return this . options . templateParameters ( compilation , assets , assetTags , this . options ) ;
346
+ if ( typeof templateParameters === 'function' ) {
347
+ return Promise
348
+ . resolve ( )
349
+ . then ( ( ) => templateParameters ( compilation , assets , assetTags , this . options ) ) ;
347
350
}
348
- if ( typeof this . options . templateParameters === 'object' ) {
349
- return this . options . templateParameters ;
351
+ if ( typeof templateParameters === 'object' ) {
352
+ return Promise . resolve ( templateParameters ) ;
350
353
}
351
354
throw new Error ( 'templateParameters has to be either a function or an object' ) ;
352
355
}
@@ -372,18 +375,17 @@ class HtmlWebpackPlugin {
372
375
*/
373
376
executeTemplate ( templateFunction , assets , assetTags , compilation ) {
374
377
// Template processing
375
- const templateParams = this . getTemplateParameters ( compilation , assets , assetTags ) ;
376
- /** @type {string|Promise<string> } */
377
- let html = '' ;
378
- try {
379
- html = templateFunction ( templateParams ) ;
380
- } catch ( e ) {
381
- compilation . errors . push ( new Error ( 'Template execution failed: ' + e ) ) ;
382
- return Promise . reject ( e ) ;
383
- }
384
- // If html is a promise return the promise
385
- // If html is a string turn it into a promise
386
- return Promise . resolve ( ) . then ( ( ) => html ) ;
378
+ const templateParamsPromise = this . getTemplateParameters ( compilation , assets , assetTags ) ;
379
+ return templateParamsPromise . then ( ( templateParams ) => {
380
+ try {
381
+ // If html is a promise return the promise
382
+ // If html is a string turn it into a promise
383
+ return templateFunction ( templateParams ) ;
384
+ } catch ( e ) {
385
+ compilation . errors . push ( new Error ( 'Template execution failed: ' + e ) ) ;
386
+ return Promise . reject ( e ) ;
387
+ }
388
+ } ) ;
387
389
}
388
390
389
391
/**
0 commit comments