@@ -23,7 +23,6 @@ import {
2323import zlib from 'zlib' ;
2424
2525import { hasValue } from '../../app/shared/empty.util' ;
26- import { ThemeConfig } from '../../config/theme.config' ;
2726import {
2827 HashedFileMapping ,
2928 ID ,
@@ -46,7 +45,7 @@ export class ServerHashedFileMapping extends HashedFileMapping {
4645 public readonly indexPath : string ;
4746 private readonly indexContent : string ;
4847
49- protected readonly headLinks : Set < HeadLink > = new Set ( ) ;
48+ protected readonly headLinks : Map < string , HeadLink > = new Map ( ) ;
5049
5150 constructor (
5251 private readonly root : string ,
@@ -71,7 +70,7 @@ export class ServerHashedFileMapping extends HashedFileMapping {
7170
7271 // remove previous files
7372 const ext = extname ( path ) ;
74- glob . GlobSync ( path . replace ( `${ ext } ` , `.*${ ext } *` ) )
73+ new glob . GlobSync ( path . replace ( `${ ext } ` , `.*${ ext } *` ) )
7574 . found
7675 . forEach ( p => rmSync ( p ) ) ;
7776
@@ -112,33 +111,30 @@ export class ServerHashedFileMapping extends HashedFileMapping {
112111 return hashPath ;
113112 }
114113
115- /**
116- * Add CSS for all configured themes to the mapping
117- * @param themeConfigurations
118- */
119- addThemeStyles ( themeConfigurations : ThemeConfig [ ] ) {
120- for ( const themeConfiguration of themeConfigurations ) {
121- const p = `${ this . root } /${ themeConfiguration . name } -theme.css` ;
122- const hp = this . add ( p ) ;
114+ addThemeStyle ( theme : string , prefetch = true ) {
115+ const path = `${ this . root } /${ theme } -theme.css` ;
116+ const hashPath = this . add ( path ) ;
123117
124- // We know this CSS is likely needed, so wecan avoid a FOUC by retrieving it in advance
125- // Angular does the same for global styles, but doesn't "know" about out themes
118+ if ( prefetch ) {
119+ // We know this CSS is likely needed, so we can avoid a FOUC by retrieving it in advance
120+ // Angular does the same for global styles, but doesn't "know" about our themes
126121 this . addHeadLink ( {
127- path : p ,
122+ path,
128123 rel : 'prefetch' ,
129124 as : 'style' ,
130125 } ) ;
131-
132- this . ensureCompressedFilesAssumingUnchangedContent ( p , hp , '.br' ) ;
133- this . ensureCompressedFilesAssumingUnchangedContent ( p , hp , '.gz' ) ;
134126 }
127+
128+ // We know theme CSS has been compressed already
129+ this . ensureCompressedFilesAssumingUnchangedContent ( path , hashPath , '.br' ) ;
130+ this . ensureCompressedFilesAssumingUnchangedContent ( path , hashPath , '.gz' ) ;
135131 }
136132
137133 /**
138134 * Include a head link for a given resource to the index HTML.
139135 */
140136 addHeadLink ( headLink : HeadLink ) {
141- this . headLinks . add ( headLink ) ;
137+ this . headLinks . set ( headLink . path , headLink ) ;
142138 }
143139
144140 private renderHeadLink ( link : HeadLink ) : string {
@@ -176,7 +172,7 @@ export class ServerHashedFileMapping extends HashedFileMapping {
176172 root . querySelector ( 'head' )
177173 . appendChild ( `<script id="${ ID } " type="application/json">${ JSON . stringify ( out ) } </script>` as any ) ;
178174
179- for ( const headLink of this . headLinks ) {
175+ for ( const headLink of this . headLinks . values ( ) ) {
180176 root . querySelector ( 'head' )
181177 . appendChild ( this . renderHeadLink ( headLink ) as any ) ;
182178 }
0 commit comments