Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

public assets v4 #9

Merged
merged 1 commit into from Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/services/ViteService.php
Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/variables/ViteVariableTrait.php
Expand Up @@ -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)
);
}

Expand Down