File tree Expand file tree Collapse file tree 1 file changed +20
-6
lines changed
Expand file tree Collapse file tree 1 file changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -30,12 +30,7 @@ public function url(string $asset, $assetPath = '/assets/build')
3030 }
3131
3232 $ manifestPath = source_path ($ assetPath . '/manifest.json ' );
33-
34- if (! file_exists ($ manifestPath )) {
35- throw new Exception ('The Vite manifest does not exist. Please run `npm run build` first or start the dev server. ' );
36- }
37-
38- $ manifest = json_decode (file_get_contents ($ manifestPath ), true );
33+ $ manifest = $ this ->loadManifest ($ manifestPath );
3934
4035 if (! isset ($ manifest [$ asset ])) {
4136 throw new Exception ('Main entry point not found in Vite manifest. ' );
@@ -62,4 +57,23 @@ public function devServer()
6257
6358 return new HtmlString (sprintf ('<script type="module" src="%s"></script> ' , "{$ devServerUrl }/@vite/client " ));
6459 }
60+
61+ private function loadManifest ($ manifestPath )
62+ {
63+ static $ manifest = [];
64+ if (array_key_exists ($ manifestPath , $ manifest )) {
65+ return $ manifest [$ manifestPath ];
66+ }
67+
68+ return $ manifest [$ manifestPath ] = $ this ->uncachedManifest ($ manifestPath );
69+ }
70+
71+ private function uncachedManifest ($ manifestPath )
72+ {
73+ if (! file_exists ($ manifestPath )) {
74+ throw new Exception ('The Vite manifest does not exist. Please run `npm run build` first or start the dev server. ' );
75+ }
76+
77+ return json_decode (file_get_contents ($ manifestPath ), true );
78+ }
6579}
You can’t perform that action at this time.
0 commit comments