-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprerender.js
More file actions
26 lines (16 loc) · 795 Bytes
/
Copy pathprerender.js
File metadata and controls
26 lines (16 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Pre-render the app into static HTML.
// pain, blood, sweat and tears
// who cursed me to javascript at 2 in the morning
import { readFileSync, writeFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { render } from "./dist/server/server-render.js";
const __dirname = dirname(fileURLToPath(import.meta.url));
const toAbsolute = (p) => resolve(__dirname, p);
const template = readFileSync(toAbsolute("dist/static/index.html"), "utf8");
// doing the SSG part
const { style, html } = render();
const appHtml = template.replace("<!--app-html-->", html).replace("<!--app-css-->", style);
const filePath = "dist/static/index.html";
writeFileSync(toAbsolute(filePath), appHtml);
console.log("pre-rendered:", filePath);