Browse Source

* allow use dev vitejs build without manifest reader

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

23
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,15 +38,19 @@ class Plugin extends PluginBase
{
app()->singleton(Bundler::class, Config::get('wpstudio.assetsmanifest::bundler'));
app()->singleton(ManifestReader::class, fn() => new ManifestReader(
Theme::getActiveTheme()->getPath(
sprintf(
'%s/%s/manifest.json',
Theme::getActiveTheme()->getDirName(),
Config::get('wpstudio.assetsmanifest::vite_path_build')
)
),
));
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(
'%s/%s/manifest.json',
Theme::getActiveTheme()->getDirName(),
Config::get('wpstudio.assetsmanifest::vite_path_build')
)
),
));
}
}
/**

10
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,7 +80,11 @@ class TwigFilters
$bundler->validateBundlerType(Bundler::BUNDLER_VITE);
assert($bundler instanceof ViteBundler);
return $bundler->getEntrypointAssets($entrypointName);
if ($bundler->isViteDevEnabled()) {
return $bundler->getScriptTag($entrypointName);
} else {
return $bundler->getEntrypointAssets($entrypointName);
}
}
public static function viteDevClientScriptTag()

8
classes/bundlers/Bundler.php

@ -13,11 +13,13 @@ 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)
{
$this->manifestReader = $manifestReader;
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