Updates
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import plugin from "bun-plugin-tailwind";
|
||||
import { readdirSync, statSync, unlinkSync } from "fs";
|
||||
import grabAllPages from "../../utils/grab-all-pages";
|
||||
import grabDirNames from "../../utils/grab-dir-names";
|
||||
@@ -7,6 +8,7 @@ import path from "path";
|
||||
import bundle from "../../utils/bundle";
|
||||
import AppNames from "../../utils/grab-app-names";
|
||||
import type { PageFiles } from "../../types";
|
||||
import isDevelopment from "../../utils/is-development";
|
||||
|
||||
const { BUNX_HYDRATION_SRC_DIR, HYDRATION_DST_DIR } = grabDirNames();
|
||||
|
||||
@@ -65,6 +67,24 @@ export default async function allPagesBundler() {
|
||||
exec_options: { stdio: "ignore" },
|
||||
});
|
||||
|
||||
// console.log(`Bundling ...`);
|
||||
|
||||
// const result = await Bun.build({
|
||||
// entrypoints,
|
||||
// outdir: HYDRATION_DST_DIR,
|
||||
// plugins: [plugin],
|
||||
// minify: true,
|
||||
// target: "browser",
|
||||
// // sourcemap: "linked",
|
||||
// define: {
|
||||
// "process.env.NODE_ENV": JSON.stringify(
|
||||
// isDevelopment() ? "development" : "production",
|
||||
// ),
|
||||
// },
|
||||
// });
|
||||
|
||||
// console.log("result", result);
|
||||
|
||||
console.timeEnd("build");
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,9 @@ export default function watcher() {
|
||||
try {
|
||||
global.RECOMPILING = true;
|
||||
|
||||
console.log(`File Changed. Rebuilding ...`);
|
||||
|
||||
await allPagesBundler();
|
||||
reloadServer();
|
||||
|
||||
global.LAST_BUILD_TIME = Date.now();
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import grabPageName from "../../../utils/grab-page-name";
|
||||
import grabRouteParams from "../../../utils/grab-route-params";
|
||||
import grabRouter from "../../../utils/grab-router";
|
||||
import type { BunextPageModule, GrabPageComponentRes } from "../../../types";
|
||||
import bundle from "../../../utils/bundle";
|
||||
import path from "path";
|
||||
import AppNames from "../../../utils/grab-app-names";
|
||||
import { existsSync } from "fs";
|
||||
@@ -110,9 +109,11 @@ export default async function grabPageComponent({
|
||||
// });
|
||||
// }
|
||||
|
||||
const module: BunextPageModule = await import(
|
||||
`${filePath}?t=${global.LAST_BUILD_TIME ?? 0}`
|
||||
);
|
||||
const module: BunextPageModule = await import(filePath);
|
||||
|
||||
// const module: BunextPageModule = await import(
|
||||
// `${filePath}?t=${global.LAST_BUILD_TIME ?? 0}`
|
||||
// );
|
||||
|
||||
const Component = module.default as FC<any>;
|
||||
const component = <Component />;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import isDevelopment from "../../../utils/is-development";
|
||||
import genWebHTML from "./generate-web-html";
|
||||
import grabPageComponent from "./grab-page-component";
|
||||
|
||||
@@ -24,11 +25,24 @@ export default async function ({ req }: Params): Promise<Response> {
|
||||
// pageProps: serverRes,
|
||||
// });
|
||||
|
||||
return new Response(html, {
|
||||
const res_opts: ResponseInit = {
|
||||
headers: {
|
||||
"Content-Type": "text/html",
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
if (isDevelopment()) {
|
||||
res_opts.headers = {
|
||||
...res_opts.headers,
|
||||
"Cache-Control": "no-cache, no-store, must-revalidate",
|
||||
Pragma: "no-cache",
|
||||
Expires: "0",
|
||||
};
|
||||
}
|
||||
|
||||
const res = new Response(html, res_opts);
|
||||
|
||||
return res;
|
||||
} catch (error: any) {
|
||||
return new Response(error.message || `Page Not Found`, {
|
||||
status: 404,
|
||||
|
||||
@@ -27,9 +27,10 @@ export default async function (params: PageDistGenParams) {
|
||||
script += `}\n`;
|
||||
|
||||
script += `let root: any = null;\n\n`;
|
||||
script += `const component = <App {...window.${ClientWindowPagePropsName}} />;\n\n`;
|
||||
script += `const container = document.getElementById("${ClientRootElementIDName}");\n\n`;
|
||||
script += `if (container) {\n`;
|
||||
script += ` root = hydrateRoot(container, <App {...window.${ClientWindowPagePropsName}} />);\n`;
|
||||
script += ` root = hydrateRoot(container, component);\n`;
|
||||
script += `}\n\n`;
|
||||
if (isDevelopment()) {
|
||||
script += `const hmr = new EventSource("/__hmr");\n`;
|
||||
@@ -37,12 +38,15 @@ export default async function (params: PageDistGenParams) {
|
||||
// script += ` console.log(\`HMR even received:\`, event);\n`;
|
||||
script += ` if (event.data && root) {\n`;
|
||||
script += ` console.log(\`HMR Changes Detected. Reloading ...\`);\n`;
|
||||
// script += ` import("${page_file}?t=" + event.data.update).then((module) => {\n`;
|
||||
// script += ` root.render(module.default);\n`;
|
||||
// script += ` })\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 += ` root = hydrateRoot(container!, component);\n`;
|
||||
// script += ` root.render(component);\n`;
|
||||
script += ` window.location.reload();\n`;
|
||||
script += ` }\n`;
|
||||
script += ` });\n`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user