fix(client-entry): verwende korrekte Asset-Pfade aus Vite-Manifest für Production-Build

This commit is contained in:
2025-10-01 22:49:57 +02:00
parent 2c2a173b96
commit f4d9f60fc9

View File

@@ -1,9 +1,33 @@
/** @jsxImportSource hono/jsx */ /** @jsxImportSource hono/jsx */
import type { Context } from "hono"; import type { Context } from "hono";
import { readFileSync } from "fs";
import { join } from "path";
import type { BlankEnv } from "hono/types"; import type { BlankEnv } from "hono/types";
export function clientEntry(c: Context<BlankEnv>) { export function clientEntry(c: Context<BlankEnv>) {
let jsFile = "/src/client/main.tsx";
let cssFile = null;
if (process.env.NODE_ENV === 'production') {
try {
// Read Vite manifest to get the correct file names
const manifestPath = join(process.cwd(), 'dist', '.vite', 'manifest.json');
const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
const entry = manifest['src/client/main.tsx'];
if (entry) {
jsFile = `/assets/${entry.file}`;
if (entry.css) {
cssFile = entry.css.map((css: string) => `/assets/${css}`);
}
}
} catch (error) {
console.warn('Could not read Vite manifest, using fallback:', error);
// Fallback to a generic path
jsFile = "/assets/index-Ccx6A0bN.js";
}
}
return c.html( return c.html(
<html lang="en"> <html lang="en">
<head> <head>
@@ -11,12 +35,15 @@ export function clientEntry(c: Context<BlankEnv>) {
<meta content="width=device-width, initial-scale=1" name="viewport" /> <meta content="width=device-width, initial-scale=1" name="viewport" />
<title>Stargirlnails Kiel</title> <title>Stargirlnails Kiel</title>
<link rel="icon" type="image/png" href="/favicon.png" /> <link rel="icon" type="image/png" href="/favicon.png" />
{cssFile && cssFile.map((css: string) => (
<link key={css} rel="stylesheet" href={css} />
))}
{process.env.NODE_ENV === 'production' ? ( {process.env.NODE_ENV === 'production' ? (
<script src="/static/main.js" type="module" /> <script src={jsFile} type="module" />
) : ( ) : (
<> <>
<script src="/@vite/client" type="module" /> <script src="/@vite/client" type="module" />
<script src="/src/client/main.tsx" type="module" /> <script src={jsFile} type="module" />
</> </>
)} )}
</head> </head>