UNPKG

ziko-server

Version:

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

21 lines (20 loc) 630 B
import {mkdir, writeFile} from 'fs/promises'; import {join, dirname} from 'path'; export async function writeToDist({route, ui, head, outDir = 'dist', entry_client_path = ''}={}) { entry_client_path = `/.client/${entry_client_path}` const out = ` <!doctype html> <html> <head> <script type="module" src="${entry_client_path}"></script> </head> <body> ${ui} </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}`); }