diff --git a/src/View/Helper/RnaHelper.php b/src/View/Helper/RnaHelper.php index d0ec08e..8dc5709 100644 --- a/src/View/Helper/RnaHelper.php +++ b/src/View/Helper/RnaHelper.php @@ -4,7 +4,6 @@ namespace Chialab\Vite\View\Helper; use Cake\View\Helper; -use function Cake\Core\pluginSplit; /** * Rna compatible helper @@ -66,11 +65,6 @@ public function devServer(?string $pluginName = null, ?array $options = []): str */ public function css(string $asset, array $options = []): string { - [$group, $asset] = pluginSplit($asset); - if ($group !== null) { - return $this->Vite->css($group . '/' . $asset, $options); - } - return $this->Vite->css($asset, $options); } @@ -83,11 +77,6 @@ public function css(string $asset, array $options = []): string */ public function script(string $asset, array $options = []): string { - [$group, $asset] = pluginSplit($asset); - if ($group !== null) { - return $this->Vite->js($group . '/' . $asset, $options); - } - return $this->Vite->js($asset, $options); } } diff --git a/src/View/Helper/ViteHelper.php b/src/View/Helper/ViteHelper.php index 69141ef..b82a980 100644 --- a/src/View/Helper/ViteHelper.php +++ b/src/View/Helper/ViteHelper.php @@ -6,6 +6,7 @@ use Cake\Core\Configure; use Cake\View\Helper; use RuntimeException; +use function Cake\Core\pluginSplit; /** * ViteHelper @@ -64,6 +65,8 @@ class ViteHelper extends Helper public function css(string $entry, array $options = []): string { $mode = $this->mode(); + $entry = $this->normalizeEntry($entry); + if ($mode === 'development') { return $this->devCss($entry, $options); } @@ -91,6 +94,7 @@ public function css(string $entry, array $options = []): string public function js(string $entry, array $options = []): string { $mode = $this->mode(); + $entry = $this->normalizeEntry($entry); if ($mode === 'development') { return $this->devJs($entry, $options); @@ -123,6 +127,22 @@ protected function devClient(): string ); } + /** + * Converts a logical entry name to the format used in the manifest. + * + * @param string $entry The logical name of the entry (e.g. "PluginName.entry"). + * @return string The manifest-compatible entry name (e.g. "PluginName/entry"). + */ + protected function normalizeEntry(string $entry): string + { + [$plugin, $name] = pluginSplit($entry); + if ($plugin === null) { + return $name; + } + + return $plugin . '/' . $name; + } + /** * In dev, return the slots for an entry from the manifest inputs. *