Updates
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import path from "path";
|
||||
import { renderToString } from "react-dom/server";
|
||||
import grabContants from "../../../utils/grab-constants";
|
||||
import grabDirNames from "../../../utils/grab-dir-names";
|
||||
import EJSON from "../../../utils/ejson";
|
||||
import type { PageDistGenParams } from "../../../types";
|
||||
import type { LivePageDistGenParams } from "../../../types";
|
||||
import isDevelopment from "../../../utils/is-development";
|
||||
|
||||
export default async function genWebHTML({
|
||||
@@ -10,16 +10,28 @@ export default async function genWebHTML({
|
||||
pageProps,
|
||||
pageName,
|
||||
module,
|
||||
}: PageDistGenParams) {
|
||||
}: LivePageDistGenParams) {
|
||||
const { ClientRootElementIDName, ClientWindowPagePropsName } =
|
||||
await grabContants();
|
||||
|
||||
const { renderToString } = await import(
|
||||
path.join(process.cwd(), "node_modules", "react-dom", "server")
|
||||
);
|
||||
|
||||
const componentHTML = renderToString(component);
|
||||
|
||||
const SCRIPT_SRC = path.join("/public/routes", pageName + ".js");
|
||||
const SCRIPT_SRC = path.join("/public/pages", pageName + ".js");
|
||||
const CSS_SRC = path.join("/public/pages", pageName + ".css");
|
||||
const { HYDRATION_DST_DIR } = grabDirNames();
|
||||
const cssExists = await Bun.file(path.join(HYDRATION_DST_DIR, pageName + ".css")).exists();
|
||||
|
||||
let html = `<!DOCTYPE html>\n`;
|
||||
|
||||
html += `<html>\n`;
|
||||
html += ` <head>\n`;
|
||||
html += ` <meta charset="utf-8" />\n`;
|
||||
if (cssExists) {
|
||||
html += ` <link rel="stylesheet" href="${CSS_SRC}" />\n`;
|
||||
}
|
||||
if (isDevelopment()) {
|
||||
html += `<script>
|
||||
const hmr = new EventSource("/__hmr");
|
||||
@@ -30,11 +42,6 @@ export default async function genWebHTML({
|
||||
});
|
||||
</script>\n`;
|
||||
}
|
||||
|
||||
html += `<html>\n`;
|
||||
html += ` <head>\n`;
|
||||
html += ` <meta charset="utf-8" />\n`;
|
||||
html += ` <title>React SSR with Bun</title>\n`;
|
||||
html += ` </head>\n`;
|
||||
html += ` <body>\n`;
|
||||
html += ` <div id="${ClientRootElementIDName}">${componentHTML}</div>\n`;
|
||||
|
||||
Reference in New Issue
Block a user