' . "\n"
. '';
}
return '';
}
function jsPreloadImports(string $entry): string {
if (isDev($entry)) {
return "";
}
$res = "";
foreach (importsUrls($entry) as $url) {
$res .= '';
}
return $res;
}
function cssTag(string $entry): string {
// not needed on dev, it's inject by Vite
if (isDev($entry)) {
return "";
}
$tags = "";
foreach (cssUrls($entry) as $url) {
$tags .= '';
}
return $tags;
}
// Helpers to locate files
function getManifest(): array {
static $urlManifest;
if ($urlManifest === null) {
// vite V5
if (find_in_path("dist/.vite/manifest.json")) {
$urlManifest = find_in_path("dist/.vite/manifest.json");
// vite V4
} else if (find_in_path("dist/manifest.json")) {
$urlManifest = find_in_path("dist/manifest.json");
}
}
if ($urlManifest) {
$content = file_get_contents($urlManifest);
return json_decode($content, true);
} else {
die('pas de fichier manifest.json');
}
}
function assetUrl(string $entry): string {
$manifest = getManifest();
return isset($manifest[$entry])
? find_in_path("dist/" . $manifest[$entry]["file"])
: "";
}
function importsUrls(string $entry): array {
$urls = [];
$manifest = getManifest();
if (!empty($manifest[$entry]["imports"])) {
foreach ($manifest[$entry]["imports"] as $imports) {
$urls[] = find_in_path("dist/" . $manifest[$imports]["file"]);
}
}
return $urls;
}
function cssUrls(string $entry): array {
$urls = [];
$manifest = getManifest();
if (!empty($manifest[$entry]["css"])) {
foreach ($manifest[$entry]["css"] as $file) {
$urls[] = find_in_path("dist/" . $file);
}
}
return $urls;
}