@@ -120,6 +120,17 @@ public function preloadFonts(): void
120120 ];
121121 }
122122
123+ /**
124+ * Register MIME types for preloading stylesheets.
125+ */
126+ public function preloadStyles (): void
127+ {
128+ $ this ->preload_types = [
129+ ...$ this ->preload_types ,
130+ 'css ' => ['type ' => 'text/css ' , 'as ' => 'style ' ],
131+ ];
132+ }
133+
123134 /**
124135 * Create preload, CSS and JS tags for the specified entry point script(s).
125136 *
@@ -208,6 +219,16 @@ private function createPreloadTags(array $chunks): string
208219
209220 // Preload assets:
210221
222+ ['extension ' => $ extension ] = pathinfo ($ chunk ->file );
223+
224+ if (isset ($ this ->preload_types [$ extension ])) {
225+ $ preload = $ this ->preload_types [$ extension ];
226+ $ type = $ preload ['type ' ];
227+ $ as = $ preload ['as ' ];
228+
229+ $ tags [] = "<link rel= \"preload \" as= \"{$ as }\" type= \"{$ type }\" href= \"{$ this ->base_path }{$ chunk ->file }\" /> " ;
230+ }
231+
211232 foreach ($ chunk ->assets as $ asset ) {
212233 $ type = substr ($ asset , strrpos ($ asset , '. ' ) + 1 );
213234
@@ -235,6 +256,10 @@ private function createStyleTags(array $chunks): string
235256 foreach ($ chunk ->css as $ css ) {
236257 $ tags [] = "<link rel= \"stylesheet \" href= \"{$ this ->base_path }{$ css }\" /> " ;
237258 }
259+
260+ if (str_ends_with ($ chunk ->file , '.css ' ) && $ chunk ->isEntry ) {
261+ $ tags [] = "<link rel= \"stylesheet \" href= \"{$ this ->base_path }{$ chunk ->file }\" /> " ;
262+ }
238263 }
239264
240265 return implode ("\n" , $ tags );
@@ -248,7 +273,7 @@ private function createScriptTags(array $chunks): string
248273 $ tags = [];
249274
250275 foreach ($ chunks as $ chunk ) {
251- if ($ chunk ->isEntry ) {
276+ if (str_ends_with ( $ chunk -> file , ' .js ' ) && $ chunk ->isEntry ) {
252277 $ tags [] = "<script type= \"module \" src= \"{$ this ->base_path }{$ chunk ->file }\"></script> " ;
253278 }
254279 }
@@ -267,7 +292,8 @@ private function findImportedChunks(array $entries): array
267292 throw new RuntimeException ("Entry not found in manifest: {$ entry }" );
268293 }
269294
270- if (! $ chunk ->isEntry ) {
295+ // only check .js and .css files, because images dont get the "isEntry" information in the manifest
296+ if ((str_ends_with ($ chunk ->file , '.js ' ) || str_ends_with ($ chunk ->file , '.css ' )) && ! $ chunk ->isEntry ) {
271297 throw new RuntimeException ("Chunk is not an entry point: {$ entry }" );
272298 }
273299
0 commit comments