From 9a8bffcd268222af5ca3d03cc97709b8e836fdec Mon Sep 17 00:00:00 2001 From: Samuel Birch Date: Wed, 29 Jun 2022 13:32:21 +0100 Subject: [PATCH] public assets --- src/services/ViteService.php | 19 ++++++++++++++++++- src/variables/ViteVariableTrait.php | 4 ++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/services/ViteService.php b/src/services/ViteService.php index 1a771c9..124da39 100755 --- a/src/services/ViteService.php +++ b/src/services/ViteService.php @@ -301,11 +301,15 @@ public function entry(string $path): string * * @return string */ - public function asset(string $path): string + public function asset(string $path, bool $public=false): string { if ($this->devServerRunning()) { return $this->devServerAsset($path); } + + if ($public) { + return $this->publicAsset($path); + } return $this->manifestAsset($path); } @@ -322,6 +326,19 @@ public function devServerAsset(string $path): string // Return a URL to the given asset return FileHelper::createUrl($this->devServerPublic, $path); } + + /** + * Return the URL for the asset from the public Vite folder + * + * @param string $path + * + * @return string + */ + public function publicAsset(string $path): string + { + // Return a URL to the given asset + return FileHelper::createUrl($this->serverPublic, $path); + } /** * Return the URL for the asset from the manifest.json file diff --git a/src/variables/ViteVariableTrait.php b/src/variables/ViteVariableTrait.php index dd4037d..00a06ae 100755 --- a/src/variables/ViteVariableTrait.php +++ b/src/variables/ViteVariableTrait.php @@ -91,10 +91,10 @@ public function entry(string $path): Markup * * @return Markup */ - public function asset(string $path): Markup + public function asset(string $path, bool $public=false): Markup { return Template::raw( - $this->viteService->asset($path) + $this->viteService->asset($path, $public) ); }