UNPKG

rasengan

Version:

The modern React Framework

21 lines (20 loc) 1.26 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { TemplateLayout } from "../../entries/server/index.js"; import { renderToString } from "../node/rendering.js"; import { resolveBuildOptions } from "./index.js"; import { ManifestManager } from "./manifest.js"; import path from "node:path"; import fs from "node:fs/promises"; export const renderIndexHTML = async (template, options) => { const { rootPath, config } = options; const buildOptions = resolveBuildOptions({}); const manifest = new ManifestManager(path.posix.join(buildOptions.buildDirectory, config.ssr ? buildOptions.clientPathDirectory : '', buildOptions.manifestPathDirectory, 'manifest.json')); // Get assets tags const assets = manifest.generateMetaTags(''); // TODO: Add the correct path // Generate html from template const html = renderToString(_jsx(TemplateLayout, { Template: template, assets: assets, isSpaMode: true })); // Render the html into an index.html file await fs.writeFile(path.posix.join(rootPath, buildOptions.buildDirectory, 'index.html'), html, 'utf-8'); // Delete the dist/assets/template.js file await fs.rm(path.posix.join(rootPath, buildOptions.buildDirectory, buildOptions.assetPathDirectory, 'template.js')); };