Skip to content

Commit

Permalink
Merge branch 'release/1.0.26' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Welch committed Jun 29, 2022
2 parents aab4ab5 + 2996f4b commit 2a0a037
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Plugin Vite Changelog

## 1.0.26 - 2022.06.29
### Fixed
* Adds a boolean as a second param to the `craft.vite.asset(url, true)` so that assets in the vite public folder can be referenced correctly from Twig ([#10](https://github.com/nystudio107/craft-plugin-vite/pull/10))

## 1.0.25 - 2022.05.15
### Fixed
* Fixed an issue where the plugin couldn't detect the Vite dev server by testing `__vite_ping` instead of `@vite/client` to determine whether the dev server is running or not ([#33](https://github.com/nystudio107/craft-vite/issues/33)) ([#8](https://github.com/nystudio107/craft-plugin-vite/issues/8))
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nystudio107/craft-plugin-vite",
"description": "Plugin Vite is the conduit between Craft CMS plugins and Vite, with manifest.json & HMR support",
"version": "1.0.25",
"version": "1.0.26",
"keywords": [
"craftcms",
"plugin",
Expand Down
19 changes: 18 additions & 1 deletion src/services/ViteService.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,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

0 comments on commit 2a0a037

Please sign in to comment.