/** * After vite build: copy dist/index.html to each main route folder for crawler/static hosting. */ import fs from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' const __dirname = path.dirname(fileURLToPath(import.meta.url)) const outDir = path.resolve(__dirname, '../dist') const ROUTES = [ '/h5', '/h5/brand', '/h5/poetry', '/h5/qingxiang', '/h5/haoke', '/h5/contact', '/brand', '/poetry', '/qingxiang', '/haoke', '/system', '/tech', '/subsidy', '/partner', '/tech-detail', '/contact', ] const indexHtml = path.join(outDir, 'index.html') if (!fs.existsSync(indexHtml)) { console.error('dist/index.html not found; run vite build first') process.exit(1) } const html = fs.readFileSync(indexHtml, 'utf8') for (const route of ROUTES) { const dir = path.join(outDir, route.replace(/^\//, '')) fs.mkdirSync(dir, { recursive: true }) fs.writeFileSync(path.join(dir, 'index.html'), html) console.log(`prerender ${route}/index.html`) } console.log('Done.')