+ vitejs support
This commit is contained in:
45
classes/bundlers/Bundler.php
Normal file
45
classes/bundlers/Bundler.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php namespace Wpstudio\AssetsManifest\Classes\Bundlers;
|
||||
|
||||
use Wpstudio\AssetsManifest\Classes\AssetsManifestException;
|
||||
use Wpstudio\AssetsManifest\Classes\ManifestReader;
|
||||
|
||||
abstract class Bundler
|
||||
{
|
||||
const BUNDLER_WEBPACK_ENCORE = 'webpack-encore';
|
||||
const BUNDLER_VITE = 'vite';
|
||||
|
||||
public static array $bundlers = [
|
||||
self::BUNDLER_WEBPACK_ENCORE => WebpackEncoreBundler::class,
|
||||
self::BUNDLER_VITE => ViteBundler::class,
|
||||
];
|
||||
|
||||
protected ManifestReader $manifestReader;
|
||||
|
||||
public function __construct(ManifestReader $manifestReader)
|
||||
{
|
||||
$this->manifestReader = $manifestReader;
|
||||
}
|
||||
|
||||
public function getBundlerType(): string
|
||||
{
|
||||
return array_flip(self::$bundlers)[get_class($this)];
|
||||
}
|
||||
|
||||
public function validateBundlerType(string $bundlerType)
|
||||
{
|
||||
if ($this->getBundlerType() != $bundlerType) {
|
||||
throw new AssetsManifestException(
|
||||
sprintf(
|
||||
'Expected bundler type is %s, but actual %s',
|
||||
$bundlerType,
|
||||
$this->getBundlerType()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function getEntrypoint(string $entrypointPathInManifest): array
|
||||
{
|
||||
return $this->manifestReader->get($entrypointPathInManifest);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user