diff --git a/package.json b/package.json index 15c42bd..d7623a5 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/scripts/prerender.mjs b/scripts/prerender.mjs index aafeb82..945c779 100644 --- a/scripts/prerender.mjs +++ b/scripts/prerender.mjs @@ -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}`;