fix(client-entry): verwende korrekte Asset-Pfade aus Vite-Manifest für Production-Build
This commit is contained in:
@@ -1,9 +1,33 @@
|
||||
/** @jsxImportSource hono/jsx */
|
||||
import type { Context } from "hono";
|
||||
import { readFileSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
import type { BlankEnv } from "hono/types";
|
||||
|
||||
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(
|
||||
<html lang="en">
|
||||
<head>
|
||||
@@ -11,12 +35,15 @@ export function clientEntry(c: Context<BlankEnv>) {
|
||||
<meta content="width=device-width, initial-scale=1" name="viewport" />
|
||||
<title>Stargirlnails Kiel</title>
|
||||
<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' ? (
|
||||
<script src="/static/main.js" type="module" />
|
||||
<script src={jsFile} type="module" />
|
||||
) : (
|
||||
<>
|
||||
<script src="/@vite/client" type="module" />
|
||||
<script src="/src/client/main.tsx" type="module" />
|
||||
<script src={jsFile} type="module" />
|
||||
</>
|
||||
)}
|
||||
</head>
|
||||
|
Reference in New Issue
Block a user