vite-ssr-vue2
Version:
Vite utility for vue2 server side rendering
68 lines (65 loc) • 1.98 kB
TypeScript
import Vue__default, { Component } from 'vue';
import { Unhead } from '@unhead/vue';
import Router from 'vue-router';
import { Store } from 'vuex';
/**
* Context that used for render server entry point for development
* It needs a production implementation for your environment.
* The context will go to the created hook parameters of the plugin
*/
interface Context {
hostname: string;
protocol: string;
url: string;
cookies: Record<string, any>;
ip: string;
memcache: number | null;
statusCode: number;
headers: Record<string, any>;
responseHeaders: Record<string, any>;
}
type HookResponse = void | {
head?: Unhead;
router?: Router;
store?: Store<any>;
inserts?: {
htmlAttrs?: string;
headTags?: string;
bodyAttrs?: string;
body?: string;
dependencies?: Array<string>;
};
context?: Record<string, any>;
app?: Vue__default;
};
type Hook = (params: {
app?: Vue__default;
url: URL | Location;
isClient: boolean;
initialState: Record<string, any>;
context?: Context;
[key: string]: any;
}) => HookResponse | Promise<HookResponse>;
interface CreatorOptions {
created?: Hook;
mounted?: Hook;
rendered?: Hook;
serializer?: (state: any) => any | Promise<any>;
shouldPreload?: (file: string, type: string) => boolean;
shouldPrefetch?: (file: string, type: string) => boolean;
mount?: {
rootContainer?: any;
hydrating?: boolean;
};
rootProps?: Record<string, any> | null;
}
type SsrRenderer = (url: string | URL, options?: {
manifest?: Record<string, string[]>;
[key: string]: any;
}) => Promise<{
html: string;
dependencies: string[];
}>;
type ClientHandler = (App: Component, options?: CreatorOptions) => Promise<void>;
type SsrHandler = (App: Component, options?: CreatorOptions) => SsrRenderer;
export { CreatorOptions as C, SsrHandler as S, ClientHandler as a, Context as b };