isEnabled()) { if (file_exists($this->manifestFile)) { $manifest = Json::decode(FileSystem::read($this->manifestFile), Json::FORCE_ARRAY); $asset = $manifest[$entrypoint]['file']; } else { trigger_error('Missing manifest file: ' . $this->manifestFile, E_USER_WARNING); } } else { $baseUrl = $this->viteServer . '/'; $asset = $entrypoint; } return $baseUrl . $asset; } /** * @throws \Nette\Utils\JsonException */ public function getCssAssets(string $entrypoint): array { $assets = []; if (!$this->isEnabled()) { if (file_exists($this->manifestFile)) { $manifest = Json::decode(FileSystem::read($this->manifestFile), Json::FORCE_ARRAY); $assets = $manifest[$entrypoint]['css'] ?? []; } else { trigger_error('Missing manifest file: ' . $this->manifestFile, E_USER_WARNING); } } return $assets; } public function isEnabled(): bool { if (!$this->productionMode && $this->httpRequest->getCookie('netteVite') === 'true') { return true; } else { return false; } } /** * @throws \Nette\Utils\JsonException */ public function printTags(string $entrypoint): void { $scripts = [$this->getAsset($entrypoint)]; $styles = $this->getCssAssets($entrypoint); if ($this->isEnabled()) { echo Html::el('script')->type('module')->src($this->viteServer . '/' . '@vite/client'); } foreach ($styles as $path) { echo Html::el('link')->rel('stylesheet')->href($path); } foreach ($scripts as $path) { echo Html::el('script')->type('module')->src($path); } } }