Skip to content

Commit

Permalink
Added fix to enable passing package name to vite twig function
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxwilko committed Jun 9, 2024
1 parent 3a98a96 commit 8a696dc
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions modules/cms/twig/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
use Cms\Classes\Controller;
use Event;
use Illuminate\Foundation\Vite;
use System\Classes\CompilableAssets;
use Twig\Extension\AbstractExtension as TwigExtension;
use Twig\TwigFilter as TwigSimpleFilter;
use Twig\TwigFunction as TwigSimpleFunction;
use Winter\Storm\Exception\SystemException;

/**
* The CMS Twig extension class implements the basic CMS Twig functions and filters.
Expand Down Expand Up @@ -172,14 +174,18 @@ public function themeFilter($url): string
* Generates Vite tags via Laravel's Vite Object.
*
* @param array $arguments The list of entry points for Vite
* @param string $base The relative base path of the plugin or theme
* @param string $package The package name of the plugin or theme
* @return \Illuminate\Support\HtmlString
*/
public function viteFunction(array $arguments, string $base): \Illuminate\Support\HtmlString
public function viteFunction(array $arguments, string $package): \Illuminate\Support\HtmlString
{
if (!($compilableAssetPackage = CompilableAssets::instance()->getPackages('vite')[$package] ?? null)) {
throw new SystemException('Unable to resolve package: ' . $package);
}

$vite = app(Vite::class);
$vite->useHotFile(base_path($base . '/public/hot'));
return $vite($arguments, $base . '/public/build');
$vite->useHotFile(base_path($compilableAssetPackage['path'] . '/public/hot'));
return $vite($arguments, $compilableAssetPackage['path'] . '/public/build');
}

/**
Expand Down

0 comments on commit 8a696dc

Please sign in to comment.