UNPKG

ziko-server

Version:

server side rendering in zikojs with file-based-routing and client side hydration

19 lines (18 loc) 534 B
import {mkdir, writeFile} from 'fs/promises'; import {join, dirname} from 'path'; export async function writeToDist({route, html, outDir = 'dist'}={}) { const out = ` <!doctype html> <html> <head> </head> <body> ${html} </body> </html> ` const filePath = join(outDir, route === '/' ? '' : route, 'index.html'); await mkdir(dirname(filePath), { recursive: true }); await writeFile(filePath, out, 'utf8'); console.log(`✔️ Saved ${route}${filePath}`); }