This commit is contained in:
Christophe 2024-07-03 21:32:39 +02:00
parent b6cc4ad586
commit 867e7993bb

View file

@ -27,8 +27,7 @@ function vite(string $entry, $port = "5134"): string {
// Some dev/prod mechanism would exist in your project // Some dev/prod mechanism would exist in your project
function isDev(string $entry): bool function isDev(string $entry): bool {
{
// This method is very useful for the local server // This method is very useful for the local server
// if we try to access it, and by any means, didn't started Vite yet // if we try to access it, and by any means, didn't started Vite yet
// it will fallback to load the production files from manifest // it will fallback to load the production files from manifest
@ -62,8 +61,7 @@ function isDev(string $entry): bool
// Helpers to print tags // Helpers to print tags
function jsTag(string $entry): string function jsTag(string $entry): string {
{
$url = isDev($entry) ? VITE_HOST . "/" . $entry : assetUrl($entry); $url = isDev($entry) ? VITE_HOST . "/" . $entry : assetUrl($entry);
if (!$url) { if (!$url) {
@ -73,8 +71,7 @@ function jsTag(string $entry): string
return '<script type="module" crossorigin src="' . $url . '"></script>'; return '<script type="module" crossorigin src="' . $url . '"></script>';
} }
function jsPreloadImports(string $entry): string function jsPreloadImports(string $entry): string {
{
if (isDev($entry)) { if (isDev($entry)) {
return ""; return "";
} }
@ -86,8 +83,7 @@ function jsPreloadImports(string $entry): string
return $res; return $res;
} }
function cssTag(string $entry): string function cssTag(string $entry): string {
{
// not needed on dev, it's inject by Vite // not needed on dev, it's inject by Vite
if (isDev($entry)) { if (isDev($entry)) {
return ""; return "";
@ -102,16 +98,14 @@ function cssTag(string $entry): string
// Helpers to locate files // Helpers to locate files
function getManifest(): array function getManifest(): array {
{
$urlManifest = find_in_path("dist/manifest.json"); $urlManifest = find_in_path("dist/manifest.json");
$content = file_get_contents($urlManifest); $content = file_get_contents($urlManifest);
return json_decode($content, true); return json_decode($content, true);
} }
function assetUrl(string $entry): string function assetUrl(string $entry): string {
{
$manifest = getManifest(); $manifest = getManifest();
return isset($manifest[$entry]) return isset($manifest[$entry])
@ -119,8 +113,7 @@ function assetUrl(string $entry): string
: ""; : "";
} }
function importsUrls(string $entry): array function importsUrls(string $entry): array {
{
$urls = []; $urls = [];
$manifest = getManifest(); $manifest = getManifest();
@ -132,8 +125,7 @@ function importsUrls(string $entry): array
return $urls; return $urls;
} }
function cssUrls(string $entry): array function cssUrls(string $entry): array {
{
$urls = []; $urls = [];
$manifest = getManifest(); $manifest = getManifest();