-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlayout.php
More file actions
43 lines (27 loc) · 1.38 KB
/
layout.php
File metadata and controls
43 lines (27 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
use function Component\useFetch;
require_once 'app/components/svgs/MenuIcon.php';
require_once 'app/components/HeaderComponent.php';
$layout = function() use (&$app) {
// --- Vite dev server origin ---
// NOTE: If you change your Vite host/port, update this AND the two dev <script> tags in index.html
$viteDevOrigin = 'http://localhost:5173';
$isProduction = getenv('APP_ENV') === 'production';
// --- Check if Vite dev server is running ---
$viteLayout = $isProduction ? false : useFetch($viteDevOrigin)->timeout(1)->get()->text();
if (!$viteLayout) {
$viteLayout = file_get_contents('index.html');
// --- Production: Load assets from manifest ---
$manifest = json_decode(file_get_contents('public/assets/.vite/manifest.json'), true);
$mainEntry = $manifest['src/main.ts'];
// --- Add CSS link tags for all imported stylesheets to the Application ---
foreach ($mainEntry['css'] ?? [] as $cssFile) {
$app?->styleSheet(content: "/assets/$cssFile", type: 'text/css');
}
// --- Add Production Javascript tags for the main Application script ---
$app?->script(content: '/assets/' . $mainEntry['file'], type: 'module');
// --- Remove dev urls from layout ---
$viteLayout = str_replace(["$viteDevOrigin/@vite/client", "$viteDevOrigin/src/main.ts"], '', $viteLayout);
}
return $viteLayout;
};