resolvePath('/public/.vite/manifest.json'); ; #$manifestPath = dirname(__DIR__, 3) . '../public/.vite/manifest.json'; if (! is_file($manifestPath)) { throw TemplateProcessorException::manifestNotFound($manifestPath); } $json = file_get_contents($manifestPath); $this->manifest = json_decode($json, true) ?? []; } public function process(DomWrapper $dom, RenderContext $context): DomWrapper { // Skip if this is a partial render (e.g. component) if ($context->isPartial ?? false) { return $dom; } // JS-Key, wie im Manifest unter "resources/js/main.js" $jsKey = 'resources/js/main.js'; // Debug: Log what we have in manifest error_log("AssetInjector: Processing with manifest: " . json_encode($this->manifest)); // Check if we have the JS key in manifest if (! isset($this->manifest[$jsKey])) { error_log("AssetInjector: Key '$jsKey' not found in manifest!"); return $dom; } // Debug: Log the CSS array if (isset($this->manifest[$jsKey]['css'])) { error_log("AssetInjector: CSS array found: " . json_encode($this->manifest[$jsKey]['css'])); } else { error_log("AssetInjector: No CSS array in manifest entry!"); } // Use DomHeadService instead of direct manipulation if (! empty($this->manifest[$jsKey]['css']) && is_array($this->manifest[$jsKey]['css'])) { foreach ($this->manifest[$jsKey]['css'] as $cssFile) { error_log("AssetInjector: Adding CSS file: " . $cssFile); $this->headService->addStylesheet($dom, '/' . ltrim($cssFile, '/')); } } // --- JS Main Script --- if (isset($this->manifest[$jsKey]['file']) && str_ends_with($this->manifest[$jsKey]['file'], '.js')) { error_log("AssetInjector: Adding JS file: " . $this->manifest[$jsKey]['file']); $this->headService->addScript($dom, '/' . ltrim($this->manifest[$jsKey]['file'], '/')); } return $dom; } }