+ hmr assets from webpack encore dev-server supports
This commit is contained in:
@ -1,8 +1,11 @@
|
||||
<?php namespace Wpstudio\AssetsManifest\Classes;
|
||||
|
||||
class ManifestReader
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class ManifestReader implements Arrayable
|
||||
{
|
||||
private $manifest = null;
|
||||
private Collection $manifest;
|
||||
|
||||
/**
|
||||
* @param string $manifestPath
|
||||
@ -18,11 +21,16 @@ class ManifestReader
|
||||
throw new AssetsManifestException('Not readable: ' . $manifestPath);
|
||||
}
|
||||
|
||||
$this->manifest = json_decode(file_get_contents($manifestPath));
|
||||
$this->manifest = collect(json_decode(file_get_contents($manifestPath)));
|
||||
}
|
||||
|
||||
public function get(string $assetName)
|
||||
{
|
||||
return $this->manifest->$assetName;
|
||||
return $this->manifest->offsetGet($assetName);
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return $this->manifest;
|
||||
}
|
||||
}
|
||||
|
@ -12,4 +12,25 @@ class TwigFilters
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user