You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.1 KiB

<?php namespace Wpstudio\AssetsManifest\Classes;
use Wpstudio\Assetsmanifest\Components\Manifest;
class TwigFilters
{
public static function manifest($assetName): string
{
$manifest = app()->get(Manifest::class);
assert($manifest instanceof Manifest);
return $manifest->getManifestReader()->get($assetName);
}
public static function hmrAssets()
{
if (\Config::get('app.debug')) {
$manifest = app()->get(Manifest::class);
assert($manifest instanceof Manifest);
$startsWithSubstring = 'vendors-node_modules';
foreach ($manifest->getManifestReader()->toArray() as $assetName => $assetsFullPath) {
if (starts_with($assetName, $startsWithSubstring)) {
if (ends_with($assetName, '.css')) {
echo '<link rel="stylesheet" href="' . $assetsFullPath . '">' . PHP_EOL;
} else {
echo '<script src="' . $assetsFullPath . '"></script>' . PHP_EOL;
}
}
}
}
}
}