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

  1. <?php namespace Wpstudio\AssetsManifest\Classes;
  2. use Wpstudio\Assetsmanifest\Components\Manifest;
  3. class TwigFilters
  4. {
  5. public static function manifest($assetName): string
  6. {
  7. $manifest = app()->get(Manifest::class);
  8. assert($manifest instanceof Manifest);
  9. return $manifest->getManifestReader()->get($assetName);
  10. }
  11. public static function hmrAssets()
  12. {
  13. if (\Config::get('app.debug')) {
  14. $manifest = app()->get(Manifest::class);
  15. assert($manifest instanceof Manifest);
  16. $startsWithSubstring = 'vendors-node_modules';
  17. foreach ($manifest->getManifestReader()->toArray() as $assetName => $assetsFullPath) {
  18. if (starts_with($assetName, $startsWithSubstring)) {
  19. if (ends_with($assetName, '.css')) {
  20. echo '<link rel="stylesheet" href="' . $assetsFullPath . '">' . PHP_EOL;
  21. } else {
  22. echo '<script src="' . $assetsFullPath . '"></script>' . PHP_EOL;
  23. }
  24. }
  25. }
  26. }
  27. }
  28. }