Updates
This commit is contained in:
parent
ec2dc0c4dc
commit
075e2f88d6
@ -28,6 +28,7 @@ export default function watcher() {
|
|||||||
global.RECOMPILING = true;
|
global.RECOMPILING = true;
|
||||||
|
|
||||||
await allPagesBundler();
|
await allPagesBundler();
|
||||||
|
reloadServer();
|
||||||
|
|
||||||
global.LAST_BUILD_TIME = Date.now();
|
global.LAST_BUILD_TIME = Date.now();
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,9 @@ export default async function genWebHTML({
|
|||||||
const SCRIPT_SRC = path.join("/public/pages", pageName + ".js");
|
const SCRIPT_SRC = path.join("/public/pages", pageName + ".js");
|
||||||
const CSS_SRC = path.join("/public/pages", pageName + ".css");
|
const CSS_SRC = path.join("/public/pages", pageName + ".css");
|
||||||
const { HYDRATION_DST_DIR } = grabDirNames();
|
const { HYDRATION_DST_DIR } = grabDirNames();
|
||||||
const cssExists = await Bun.file(path.join(HYDRATION_DST_DIR, pageName + ".css")).exists();
|
const cssExists = await Bun.file(
|
||||||
|
path.join(HYDRATION_DST_DIR, pageName + ".css"),
|
||||||
|
).exists();
|
||||||
|
|
||||||
let html = `<!DOCTYPE html>\n`;
|
let html = `<!DOCTYPE html>\n`;
|
||||||
html += `<html>\n`;
|
html += `<html>\n`;
|
||||||
@ -32,16 +34,16 @@ export default async function genWebHTML({
|
|||||||
if (cssExists) {
|
if (cssExists) {
|
||||||
html += ` <link rel="stylesheet" href="${CSS_SRC}" />\n`;
|
html += ` <link rel="stylesheet" href="${CSS_SRC}" />\n`;
|
||||||
}
|
}
|
||||||
if (isDevelopment()) {
|
// if (isDevelopment()) {
|
||||||
html += `<script>
|
// html += `<script>
|
||||||
const hmr = new EventSource("/__hmr");
|
// const hmr = new EventSource("/__hmr");
|
||||||
hmr.addEventListener("update", (event) => {
|
// hmr.addEventListener("update", (event) => {
|
||||||
if (event.data === "reload") {
|
// if (event.data === "reload") {
|
||||||
window.location.reload();
|
// window.location.reload();
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
</script>\n`;
|
// </script>\n`;
|
||||||
}
|
// }
|
||||||
html += ` </head>\n`;
|
html += ` </head>\n`;
|
||||||
html += ` <body>\n`;
|
html += ` <body>\n`;
|
||||||
html += ` <div id="${ClientRootElementIDName}">${componentHTML}</div>\n`;
|
html += ` <div id="${ClientRootElementIDName}">${componentHTML}</div>\n`;
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import genWebHTML from "./generate-web-html";
|
import genWebHTML from "./generate-web-html";
|
||||||
import grabPageComponent from "./grab-page-component";
|
import grabPageComponent from "./grab-page-component";
|
||||||
import writeWebPageHydrationScript from "./write-web-page-hydration-script";
|
|
||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
req: Request;
|
req: Request;
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import path from "path";
|
|||||||
import grabDirNames from "../../../utils/grab-dir-names";
|
import grabDirNames from "../../../utils/grab-dir-names";
|
||||||
import grabContants from "../../../utils/grab-constants";
|
import grabContants from "../../../utils/grab-constants";
|
||||||
import type { PageDistGenParams } from "../../../types";
|
import type { PageDistGenParams } from "../../../types";
|
||||||
|
import isDevelopment from "../../../utils/is-development";
|
||||||
|
|
||||||
const { BUNX_HYDRATION_SRC_DIR } = grabDirNames();
|
const { BUNX_HYDRATION_SRC_DIR } = grabDirNames();
|
||||||
|
|
||||||
@ -25,8 +26,26 @@ export default async function (params: PageDistGenParams) {
|
|||||||
script += ` }\n`;
|
script += ` }\n`;
|
||||||
script += `}\n`;
|
script += `}\n`;
|
||||||
|
|
||||||
script += `const container = document.getElementById("${ClientRootElementIDName}");\n`;
|
script += `let root: any = null;\n\n`;
|
||||||
script += `hydrateRoot(container, <App {...window.${ClientWindowPagePropsName}} />);\n`;
|
script += `const container = document.getElementById("${ClientRootElementIDName}");\n\n`;
|
||||||
|
script += `if (container) {\n`;
|
||||||
|
script += ` root = hydrateRoot(container, <App {...window.${ClientWindowPagePropsName}} />);\n`;
|
||||||
|
script += `}\n\n`;
|
||||||
|
if (isDevelopment()) {
|
||||||
|
script += `const hmr = new EventSource("/__hmr");\n`;
|
||||||
|
script += `hmr.addEventListener("update", (event) => {\n`;
|
||||||
|
// script += ` console.log(\`HMR even received:\`, event);\n`;
|
||||||
|
script += ` if (event.data && root) {\n`;
|
||||||
|
script += ` console.log(\`HMR Changes Detected. Reloading ...\`);\n`;
|
||||||
|
// script += ` console.log("root", root);\n`;
|
||||||
|
// script += ` root.unmount();\n`;
|
||||||
|
// script += ` const container = document.getElementById("${ClientRootElementIDName}");\n\n`;
|
||||||
|
// script += ` root = hydrateRoot(container!, <App {...window.${ClientWindowPagePropsName}} />);\n`;
|
||||||
|
script += ` root.render(<App {...window.${ClientWindowPagePropsName}} />);\n`;
|
||||||
|
// script += ` window.location.reload();\n`;
|
||||||
|
script += ` }\n`;
|
||||||
|
script += ` });\n`;
|
||||||
|
}
|
||||||
|
|
||||||
const SRC_WRITE_FILE = path.join(BUNX_HYDRATION_SRC_DIR, pageSrcTsFileName);
|
const SRC_WRITE_FILE = path.join(BUNX_HYDRATION_SRC_DIR, pageSrcTsFileName);
|
||||||
writeFileSync(SRC_WRITE_FILE, script, "utf-8");
|
writeFileSync(SRC_WRITE_FILE, script, "utf-8");
|
||||||
|
|||||||
@ -1,7 +1,13 @@
|
|||||||
export default function isDevelopment() {
|
export default function isDevelopment() {
|
||||||
const config = global.CONFIG;
|
const config = global.CONFIG;
|
||||||
|
|
||||||
if (config.development) return true;
|
if (process.env.NODE_ENV == "production") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.development) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user