PSR
This commit is contained in:
parent
b6cc4ad586
commit
867e7993bb
1 changed files with 8 additions and 16 deletions
24
inc/vite.php
24
inc/vite.php
|
@ -27,8 +27,7 @@ function vite(string $entry, $port = "5134"): string {
|
|||
|
||||
// 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
|
||||
// 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
|
||||
|
@ -62,8 +61,7 @@ function isDev(string $entry): bool
|
|||
|
||||
// Helpers to print tags
|
||||
|
||||
function jsTag(string $entry): string
|
||||
{
|
||||
function jsTag(string $entry): string {
|
||||
$url = isDev($entry) ? VITE_HOST . "/" . $entry : assetUrl($entry);
|
||||
|
||||
if (!$url) {
|
||||
|
@ -73,8 +71,7 @@ function jsTag(string $entry): string
|
|||
return '<script type="module" crossorigin src="' . $url . '"></script>';
|
||||
}
|
||||
|
||||
function jsPreloadImports(string $entry): string
|
||||
{
|
||||
function jsPreloadImports(string $entry): string {
|
||||
if (isDev($entry)) {
|
||||
return "";
|
||||
}
|
||||
|
@ -86,8 +83,7 @@ function jsPreloadImports(string $entry): string
|
|||
return $res;
|
||||
}
|
||||
|
||||
function cssTag(string $entry): string
|
||||
{
|
||||
function cssTag(string $entry): string {
|
||||
// not needed on dev, it's inject by Vite
|
||||
if (isDev($entry)) {
|
||||
return "";
|
||||
|
@ -102,16 +98,14 @@ function cssTag(string $entry): string
|
|||
|
||||
// Helpers to locate files
|
||||
|
||||
function getManifest(): array
|
||||
{
|
||||
function getManifest(): array {
|
||||
$urlManifest = find_in_path("dist/manifest.json");
|
||||
|
||||
$content = file_get_contents($urlManifest);
|
||||
return json_decode($content, true);
|
||||
}
|
||||
|
||||
function assetUrl(string $entry): string
|
||||
{
|
||||
function assetUrl(string $entry): string {
|
||||
$manifest = getManifest();
|
||||
|
||||
return isset($manifest[$entry])
|
||||
|
@ -119,8 +113,7 @@ function assetUrl(string $entry): string
|
|||
: "";
|
||||
}
|
||||
|
||||
function importsUrls(string $entry): array
|
||||
{
|
||||
function importsUrls(string $entry): array {
|
||||
$urls = [];
|
||||
$manifest = getManifest();
|
||||
|
||||
|
@ -132,8 +125,7 @@ function importsUrls(string $entry): array
|
|||
return $urls;
|
||||
}
|
||||
|
||||
function cssUrls(string $entry): array
|
||||
{
|
||||
function cssUrls(string $entry): array {
|
||||
$urls = [];
|
||||
$manifest = getManifest();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue