import type { App } from 'vue' import type { Router, RouteRecordRaw, RouterOptions as VueRouterOptions } from 'vue-router' import type { HeadClient } from '@vueuse/head' import type { Options as CrittersOptions } from 'critters' export interface ViteSSGOptions { /** * Rewrite scripts loading mode, only works for `type="module"` * * @default 'sync' */ script?: 'sync' | 'async' | 'defer' | 'async defer' /** * The path of main entry, relative to the project root * * @default 'src/main.ts' */ entry?: string /** * Mock browser global variables (window, document, etc.) for SSG * * @default false */ mock?: boolean /** * Applying formatter to the generated index file. * * @default 'none' */ formatting?: 'minify' | 'prettify' | 'none' /** * Vite enviroument mode */ mode?: string /** * Options for critters * * @see https://github.com/GoogleChromeLabs/critters */ crittersOptions?: CrittersOptions | false /** * Custom functions to modified the routes to do the SSG. * * Default to a handler that filter out all the dynamic routes, * when passing your custom handler, you should also take care the dynamic routes yourself. */ includedRoutes?: (routes: string[]) => Promise | string[] /** * Callback to be called before every page render. * * Also give the change to transform the index html passed to the renderer. */ onBeforePageRender?: (route: string, indexHTML: string) => Promise | string | null | undefined /** * Callback to be called on every page rendered. * * Also give the change to transform the rendered html by returning a string. */ onPageRendered?: (route: string, renderedHTML: string) => Promise | string | null | undefined onFinished?: () => void } type PartialKeys = Omit & Partial> export interface ViteSSGContext { app: App router: HasRouter extends true ? Router : undefined routes: HasRouter extends true ? RouteRecordRaw[] : undefined initialState: Record head: HeadClient | undefined isClient: boolean /** * Current router path on SSG, `undefined` on client side. */ routePath?: string } export interface ViteSSGClientOptions { transformState?: (state: any) => any registerComponents?: boolean useHead?: boolean rootContainer?: string | Element } export type RouterOptions = PartialKeys & { base?: string } // extend vite.config.ts declare module 'vite' { interface UserConfig { ssgOptions?: ViteSSGOptions } }