fix: frontend build

This commit is contained in:
Steven
2024-11-05 21:15:13 +08:00
parent e25792be9c
commit 57c00734e2
3 changed files with 32 additions and 21 deletions

View File

@@ -1,4 +1,3 @@
import mermaid from "mermaid";
import { useEffect, useRef } from "react";
interface Props {
@@ -7,18 +6,21 @@ interface Props {
const MermaidBlock: React.FC<Props> = ({ content }: Props) => {
const mermaidDockBlock = useRef<null>(null);
mermaid.initialize({ startOnLoad: false, theme: "default" });
useEffect(() => {
if (!mermaidDockBlock.current) {
return;
}
// Dynamically import mermaid to ensure compatibility with Vite
const initializeMermaid = async () => {
const mermaid = (await import("mermaid")).default;
mermaid.initialize({ startOnLoad: false, theme: "default" });
if (mermaidDockBlock.current) {
mermaid.run({
nodes: [mermaidDockBlock.current],
});
}
};
// Render mermaid when mounted.
mermaid.run({
nodes: [mermaidDockBlock.current],
});
});
initializeMermaid();
}, [content]);
return (
<pre ref={mermaidDockBlock} className="w-full p-2 whitespace-pre-wrap relative">

View File

@@ -34,4 +34,13 @@ export default defineConfig({
"@/": `${resolve(__dirname, "src")}/`,
},
},
build: {
rollupOptions: {
output: {
entryFileNames: "app.[hash].js",
chunkFileNames: "assets/chunk-vendors.[hash].js",
assetFileNames: "assets/[name].[hash][extname]",
},
},
},
});