Enable SPA prerendering in build pipeline
- Add puppeteer + mime-types to devDependencies - Integrate prerender.mjs into build script (runs after vite build) - Add Linux/Docker-safe Chrome flags (--disable-setuid-sandbox, --disable-dev-shm-usage, --disable-gpu) - Fix static server to strip query strings from URLs Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
272839d7a9
commit
4fc85ef99e
2 changed files with 13 additions and 3 deletions
|
|
@ -5,7 +5,7 @@
|
|||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "tinacms dev -c \"vite\"",
|
||||
"build": "tinacms build && node scripts/sync-blog.mjs && node scripts/generate-sitemap.mjs && tsc -b && vite build",
|
||||
"build": "tinacms build && node scripts/sync-blog.mjs && node scripts/generate-sitemap.mjs && tsc -b && vite build && node scripts/prerender.mjs",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview",
|
||||
"sync-blog": "node scripts/sync-blog.mjs",
|
||||
|
|
@ -33,6 +33,8 @@
|
|||
"eslint-plugin-react-hooks": "^7.0.1",
|
||||
"eslint-plugin-react-refresh": "^0.4.24",
|
||||
"globals": "^16.5.0",
|
||||
"mime-types": "^2.1.35",
|
||||
"puppeteer": "^24.0.0",
|
||||
"typescript": "~5.9.3",
|
||||
"typescript-eslint": "^8.48.0",
|
||||
"vite": "^7.3.1"
|
||||
|
|
|
|||
|
|
@ -42,7 +42,8 @@ async function prerender() {
|
|||
// Simple static file server for dist/
|
||||
const PORT = 5199;
|
||||
const server = createServer((req, res) => {
|
||||
let filePath = join(distDir, req.url === '/' ? '/index.html' : req.url);
|
||||
const urlPath = req.url.split('?')[0];
|
||||
let filePath = join(distDir, urlPath === '/' ? '/index.html' : urlPath);
|
||||
// For SPA routes, serve index.html
|
||||
if (!existsSync(filePath) || !extname(filePath)) {
|
||||
filePath = join(distDir, 'index.html');
|
||||
|
|
@ -55,7 +56,14 @@ async function prerender() {
|
|||
await new Promise(r => server.listen(PORT, r));
|
||||
console.log(`Static server running on http://localhost:${PORT}`);
|
||||
|
||||
const browser = await puppeteer.launch({ args: ['--no-sandbox'] });
|
||||
const browser = await puppeteer.launch({
|
||||
args: [
|
||||
'--no-sandbox',
|
||||
'--disable-setuid-sandbox',
|
||||
'--disable-dev-shm-usage',
|
||||
'--disable-gpu',
|
||||
],
|
||||
});
|
||||
|
||||
for (const route of routes) {
|
||||
const url = `http://localhost:${PORT}${route}`;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue