import { readFileSync, writeFileSync, rmSync, readdirSync } from 'fs' import { resolve, dirname } from 'path' import { fileURLToPath } from 'url' const __dirname = dirname(fileURLToPath(import.meta.url)) const root = resolve(__dirname, '..') // Import SSR bundle built by vite build --ssr const { render } = await import('../dist/server/entry-server.js') let html = readFileSync(resolve(root, 'dist/index.html'), 'utf-8') // Inject prerendered HTML const appHtml = render() html = html.replace('
', `
${appHtml}
`) // Fix preload font: find actual cyrillic-700 woff2 hash in dist/assets const assetsDir = resolve(root, 'dist/assets') const fontFile = readdirSync(assetsDir).find(f => f.match(/manrope-cyrillic-700-normal-.+\.woff2/)) if (fontFile) { html = html.replace( /href="\/assets\/manrope-cyrillic-700-normal-[^"]+\.woff2"/, `href="/assets/${fontFile}"` ) console.log(`✓ Preload font updated: ${fontFile}`) } writeFileSync(resolve(root, 'dist/index.html'), html) // Cleanup SSR bundle rmSync(resolve(root, 'dist/server'), { recursive: true, force: true }) console.log('✓ Prerendered index.html')