Browse Source

* allow use dev vitejs build without manifest reader

develop 2.0.0
dimti 2 years ago
parent
commit
2c2c419332
  1. 5
      Plugin.php
  2. 8
      classes/TwigFilters.php
  3. 6
      classes/bundlers/Bundler.php
  4. 8
      classes/bundlers/ViteBundler.php

5
Plugin.php

@ -4,6 +4,7 @@ use Backend;
use Cms\Classes\Theme;
use System\Classes\PluginBase;
use Wpstudio\AssetsManifest\Classes\Bundlers\Bundler;
use Wpstudio\AssetsManifest\Classes\Bundlers\ViteBundler;
use Wpstudio\AssetsManifest\Classes\ManifestReader;
use Wpstudio\AssetsManifest\Classes\TwigFilters;
use Config;
@ -37,6 +38,9 @@ class Plugin extends PluginBase
{
app()->singleton(Bundler::class, Config::get('wpstudio.assetsmanifest::bundler'));
if (Config::get('wpstudio.assetsmanifest::vite_dev_enabled') != ViteBundler::class ||
!Config::get('wpstudio.assetsmanifest::vite_dev_enabled')
) {
app()->singleton(ManifestReader::class, fn() => new ManifestReader(
Theme::getActiveTheme()->getPath(
sprintf(
@ -47,6 +51,7 @@ class Plugin extends PluginBase
),
));
}
}
/**
* Boot method, called right before the request route.

8
classes/TwigFilters.php

@ -61,6 +61,10 @@ class TwigFilters
$bundler->validateBundlerType(Bundler::BUNDLER_VITE);
assert($bundler instanceof ViteBundler);
if ($bundler->isViteDevEnabled()) {
return '';
}
return $bundler->getEntrypointStylesheets($entrypointName);
}
@ -76,8 +80,12 @@ class TwigFilters
$bundler->validateBundlerType(Bundler::BUNDLER_VITE);
assert($bundler instanceof ViteBundler);
if ($bundler->isViteDevEnabled()) {
return $bundler->getScriptTag($entrypointName);
} else {
return $bundler->getEntrypointAssets($entrypointName);
}
}
public static function viteDevClientScriptTag()
{

6
classes/bundlers/Bundler.php

@ -13,12 +13,14 @@ abstract class Bundler
self::BUNDLER_VITE => ViteBundler::class,
];
protected ManifestReader $manifestReader;
protected ?ManifestReader $manifestReader;
public function __construct(ManifestReader $manifestReader)
public function __construct(?ManifestReader $manifestReader = null)
{
if (isset($manifestReader)) {
$this->manifestReader = $manifestReader;
}
}
public function getBundlerType(): string
{

8
classes/bundlers/ViteBundler.php

@ -60,10 +60,6 @@ class ViteBundler extends Bundler
*/
public function getEntrypointStylesheets(string $entrypointName): string
{
if ($this->isViteDevEnabled()) {
return '';
}
$entrypoint = $this->getViteEntrypoint($entrypointName);
$stylesheetTags = collect();
@ -85,7 +81,7 @@ class ViteBundler extends Bundler
return $stylesheetTags->implode(PHP_EOL);
}
private function getStylesheetTag(string $href): string
public function getStylesheetTag(string $href): string
{
return sprintf(
'<link rel="stylesheet" href="%s">',
@ -93,7 +89,7 @@ class ViteBundler extends Bundler
);
}
private function getScriptTag(string $entrypointName, ViteEntrypoint $entrypoint): string
public function getScriptTag(string $entrypointName, ?ViteEntrypoint $entrypoint = null): string
{
return sprintf(
'<script type="module" src="%s" %s></script>',

Loading…
Cancel
Save