Files
dukang_official/scripts/prerender-routes.mjs
T
2026-08-26 00:44:25 +08:00

38 lines
944 B
JavaScript

/**
* 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 = [
'/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.')