@@ -13,27 +13,32 @@ class Vite
1313 /**
1414 * Get vite entry file on running or bundled files instead.
1515 *
16- * @return string single script tag on developing and much more on production
16+ * @return array single script tag on developing and much more on production
1717 */
18- public static function tags (): ?string
18+ public static function tags (): ?array
1919 {
20+ $ result = [
21+ 'js ' => null ,
22+ 'css ' => null
23+ ];
24+
2025 # Check if vite is running.
2126 $ entryFile = env ('VITE_ORIGIN ' ) . '/ ' . env ('VITE_RESOURCES_DIR ' ) . '/ ' . env ('VITE_ENTRY_FILE ' );
2227
23- $ result = @file_get_contents ($ entryFile ) ? '<script type="module" src=" ' . $ entryFile . '"></script> ' : null ;
28+ $ result[ ' js ' ] = @file_get_contents ($ entryFile ) ? '<script type="module" src=" ' . $ entryFile . '"></script> ' : null ;
2429
2530 # React HMR fix.
26- if (!empty ($ result ))
31+ if (!empty ($ result[ ' js ' ] ))
2732 {
28- $ result = self ::getReactTag () . " $ result" ;
33+ $ result[ ' js ' ] = self ::getReactTag () . $ result[ ' js ' ] ;
2934 }
3035
31- # If vite isn't running, then return the compiled resources.
32- if (empty ($ result ) && is_file (self ::$ manifest ))
36+ # If vite isn't running, then return the bundled resources.
37+ if (empty ($ result[ ' js ' ] ) && is_file (self ::$ manifest ))
3338 {
3439 # Get the manifest content.
3540 $ manifest = file_get_contents (self ::$ manifest );
36- # You look much pretty as an php object =).
41+ # You look much pretty as a php object =).
3742 $ manifest = json_decode ($ manifest );
3843
3944 # Now, we will get all js files and css from the manifest.
@@ -45,14 +50,14 @@ public static function tags(): ?string
4550 # Generate js tag.
4651 if ($ fileExtension === '.js ' && isset ($ file ->isEntry ) && $ file ->isEntry === true )
4752 {
48- $ result .= '<script type="module" src="/ ' . $ file ->file . '"></script> ' ;
53+ $ result[ ' js ' ] .= '<script type="module" src="/ ' . $ file ->file . '"></script> ' ;
4954 }
5055
5156 if (!empty ($ file ->css ))
5257 {
5358 foreach ($ file ->css as $ cssFile )
5459 {
55- $ result .= '<link rel="stylesheet" href="/ ' . $ cssFile . '" /> ' ;
60+ $ result[ ' css ' ] .= '<link rel="stylesheet" href="/ ' . $ cssFile . '" /> ' ;
5661 }
5762 }
5863 }
0 commit comments