@@ -13,7 +13,7 @@ import { NormalizedOptimizationOptions } from '../normalize-optimization';
1313import { addEventDispatchContract } from './add-event-dispatch-contract' ;
1414import { CrossOriginValue , Entrypoint , FileInfo , augmentIndexHtml } from './augment-index-html' ;
1515import { autoCsp } from './auto-csp' ;
16- import { InlineCriticalCssProcessor } from './inline-critical-css' ;
16+ import { inlineCriticalCss } from './inline-critical-css' ;
1717import { InlineFontsProcessor } from './inline-fonts' ;
1818import { addNgcmAttribute } from './ngcm-attribute' ;
1919import { addNonce } from './nonce' ;
@@ -28,7 +28,6 @@ export type HintMode = 'prefetch' | 'preload' | 'modulepreload' | 'preconnect' |
2828export interface IndexHtmlGeneratorProcessOptions {
2929 lang : string | undefined ;
3030 baseHref : string | undefined ;
31- outputPath : string ;
3231 files : FileInfo [ ] ;
3332 hints ?: { url : string ; mode : HintMode ; as ?: string } [ ] ;
3433}
@@ -49,6 +48,7 @@ export interface IndexHtmlGeneratorOptions {
4948 imageDomains ?: string [ ] ;
5049 generateDedicatedSSRContent ?: boolean ;
5150 autoCsp ?: AutoCspOptions ;
51+ outputPath : string ;
5252
5353 /**
5454 * Integrity metadata for module URLs not directly referenced in the index
@@ -89,7 +89,7 @@ export class IndexHtmlGenerator {
8989
9090 // CSR plugins
9191 if ( options ?. optimization ?. styles ?. inlineCritical ) {
92- this . csrPlugins . push ( inlineCriticalCssPlugin ( this , ! ! options . autoCsp ) ) ;
92+ this . csrPlugins . push ( inlineCriticalCssPlugin ( this ) ) ;
9393 }
9494
9595 this . csrPlugins . push ( addNoncePlugin ( ) ) ;
@@ -182,10 +182,11 @@ function augmentIndexHtmlPlugin(generator: IndexHtmlGenerator): IndexHtmlGenerat
182182 entrypoints,
183183 imageDomains,
184184 chunksIntegrity,
185+ outputPath,
185186 } = generator . options ;
186187
187- return async ( html , options ) => {
188- const { lang, baseHref, outputPath = '' , files, hints } = options ;
188+ return ( html , options ) => {
189+ const { lang, baseHref, files, hints } = options ;
189190
190191 return augmentIndexHtml ( {
191192 html,
@@ -209,22 +210,15 @@ function inlineFontsPlugin({ options }: IndexHtmlGenerator): IndexHtmlGeneratorP
209210 minify : options . optimization ?. styles . minify ,
210211 } ) ;
211212
212- return async ( html ) => inlineFontsProcessor . process ( html ) ;
213+ return ( html ) => inlineFontsProcessor . process ( html ) ;
213214}
214215
215- function inlineCriticalCssPlugin (
216- generator : IndexHtmlGenerator ,
217- autoCsp : boolean ,
218- ) : IndexHtmlGeneratorPlugin {
219- const inlineCriticalCssProcessor = new InlineCriticalCssProcessor ( {
220- minify : generator . options . optimization ?. styles . minify ,
221- deployUrl : generator . options . deployUrl ,
222- readAsset : ( filePath ) => generator . readAsset ( filePath ) ,
223- autoCsp,
224- } ) ;
216+ function inlineCriticalCssPlugin ( generator : IndexHtmlGenerator ) : IndexHtmlGeneratorPlugin {
217+ const { outputPath, deployUrl, optimization } = generator . options ;
218+ const { minify = false } = optimization ?. styles ?? { } ;
225219
226- return async ( html , options ) =>
227- inlineCriticalCssProcessor . process ( html , { outputPath : options . outputPath } ) ;
220+ return ( html ) =>
221+ inlineCriticalCss ( html , outputPath , deployUrl , minify , ( path ) => generator . readAsset ( path ) ) ;
228222}
229223
230224function addNoncePlugin ( ) : IndexHtmlGeneratorPlugin {
0 commit comments