Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions src/View/Helper/RnaHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace Chialab\Vite\View\Helper;

use Cake\View\Helper;
use function Cake\Core\pluginSplit;

/**
* Rna compatible helper
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
}
20 changes: 20 additions & 0 deletions src/View/Helper/ViteHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Cake\Core\Configure;
use Cake\View\Helper;
use RuntimeException;
use function Cake\Core\pluginSplit;

/**
* ViteHelper
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
*
Expand Down
Loading