@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 (31 loc) • 930 B
text/typescript
import type { IndexHtmlTransformHook, Plugin } from "vite";
export function resolveHtmlTransforms(
plugins: readonly Plugin[],
): [
IndexHtmlTransformHook[],
IndexHtmlTransformHook[],
IndexHtmlTransformHook[],
] {
const preHooks: IndexHtmlTransformHook[] = [];
const normalHooks: IndexHtmlTransformHook[] = [];
const postHooks: IndexHtmlTransformHook[] = [];
for (const plugin of plugins) {
const hook = plugin.transformIndexHtml;
if (!hook) continue;
if (typeof hook === "function") {
normalHooks.push(hook);
} else {
const order = hook.order;
// @ts-expect-error union type
const handler = hook.handler ?? hook.transform;
if (order === "pre") {
preHooks.push(handler);
} else if (order === "post") {
postHooks.push(handler);
} else {
normalHooks.push(handler);
}
}
}
return [preHooks, normalHooks, postHooks];
}