forked from rdyplayerB/quip-linktree
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprerender.mjs
More file actions
23 lines (17 loc) · 752 Bytes
/
Copy pathprerender.mjs
File metadata and controls
23 lines (17 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { readFileSync, writeFileSync, rmSync } from 'node:fs';
import { resolve } from 'node:path';
import { pathToFileURL } from 'node:url';
const serverEntry = resolve('build-ssr/entry-server.js');
const { render } = await import(pathToFileURL(serverEntry).href);
const appHtml = render();
const template = readFileSync('dist/index.html', 'utf-8');
const placeholder = '<div id="root"></div>';
if (!template.includes(placeholder)) {
throw new Error(`Expected ${placeholder} in dist/index.html`);
}
writeFileSync(
'dist/index.html',
template.replace(placeholder, `<div id="root">${appHtml}</div>`),
);
rmSync('build-ssr', { recursive: true, force: true });
console.log(`Prerendered dist/index.html (${appHtml.length} bytes of app HTML)`);