UNPKG

@wroud/vite-plugin-ssg

Version:

A Vite plugin for static site generation (SSG) with React. Renders React applications to static HTML for faster load times and improved SEO.

36 lines 1.57 kB
import { jsx as _jsx } from "react/jsx-runtime"; /// <reference lib="dom" /> import { hydrateRoot } from "react-dom/client"; import { AppInstance } from "../app/AppInstance.js"; import { renderViteTags } from "./ssg-common.js"; import { AppContext } from "./components/AppContext.js"; import { SSGContext } from "./components/SSGContext.js"; export async function create(indexOrApp, context, mainScriptUrl) { context = getContext(context); if (!(indexOrApp instanceof AppInstance)) { indexOrApp = new AppInstance(indexOrApp); } const appStartData = await indexOrApp.start(context); context.base = appStartData.base; return { appStartData, context, async hydrate(htmlTags) { const renderTags = renderViteTags.bind(undefined, htmlTags, context); const Index = indexOrApp.index; hydrateRoot(document, _jsx(AppContext, { value: appStartData, children: _jsx(SSGContext, { value: { context, renderTags, mainScriptUrl }, children: _jsx(Index, { renderTags: renderTags, context: context, mainScriptUrl: mainScriptUrl }) }) })); }, }; } function getContext(initialContext) { initialContext.base = document.querySelector("meta[property='base']")?.getAttribute("content") || undefined; initialContext.cspNonce = document .querySelector("meta[property='csp-nonce']") ?.getAttribute("nonce") || undefined; initialContext.href = window.location.href; return initialContext; } //# sourceMappingURL=client.js.map