Skip to content

Commit

Permalink
fix #63 add vite_mode twig function
Browse files Browse the repository at this point in the history
  • Loading branch information
lhapaipai committed Aug 31, 2023
1 parent fa6e9ee commit 0ef2fe9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v4.2.0

- add `vite_mode` twig function

## v4.0.1

- fix conditional imports generate modulepreloads for everything
Expand Down
9 changes: 9 additions & 0 deletions src/Asset/EntrypointRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ public function renderLinks(string $entryName, array $options = [], $buildName =
return implode(PHP_EOL, $content);
}

public function getMode(string $buildName = null): ?string
{
if (!$this->entrypointsLookup->hasFile($buildName)) {
return null;
}

return $this->entrypointsLookup->isProd() ? 'prod' : 'dev';
}

public function reset()
{
// resets the state of this service
Expand Down
6 changes: 6 additions & 0 deletions src/Twig/EntryFilesTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ public function getFunctions(): array
return [
new TwigFunction('vite_entry_script_tags', [$this, 'renderViteScriptTags'], ['is_safe' => ['html']]),
new TwigFunction('vite_entry_link_tags', [$this, 'renderViteLinkTags'], ['is_safe' => ['html']]),
new TwigFunction('vite_mode', [$this, 'getViteMode']),
];
}

public function getViteMode(string $buildName = null): ?string
{
return $this->entrypointRenderer->getMode($buildName);
}

public function renderViteScriptTags(string $entryName, array $options = [], $buildName = null): string
{
return $this->entrypointRenderer->renderScripts($entryName, $options, $buildName);
Expand Down

0 comments on commit 0ef2fe9

Please sign in to comment.