UNPKG

1.63 kBTypeScriptView Raw
1import Vue, { VNode, VNodeDirective } from 'vue'
2import { Readable } from 'stream'
3
4export declare function createRenderer(options?: RendererOptions): Renderer
5
6export declare function createBundleRenderer(
7 bundle: string | object,
8 options?: BundleRendererOptions
9): BundleRenderer
10
11type RenderCallback = (err: Error | null, html: string) => void
12
13interface Renderer {
14 renderToString(vm: Vue, callback: RenderCallback): void
15 renderToString(vm: Vue, context: object, callback: RenderCallback): void
16 renderToString(vm: Vue): Promise<string>
17 renderToString(vm: Vue, context: object): Promise<string>
18
19 renderToStream(vm: Vue, context?: object): Readable
20}
21
22interface BundleRenderer {
23 renderToString(callback: RenderCallback): void
24 renderToString(context: object, callback: RenderCallback): void
25 renderToString(): Promise<string>
26 renderToString(context: object): Promise<string>
27
28 renderToStream(context?: object): Readable
29}
30
31interface RendererOptions {
32 template?: string
33 inject?: boolean
34 shouldPreload?: (file: string, type: string) => boolean
35 shouldPrefetch?: (file: string, type: string) => boolean
36 cache?: RenderCache
37 directives?: {
38 [key: string]: (vnode: VNode, dir: VNodeDirective) => void
39 }
40}
41
42interface BundleRendererOptions extends RendererOptions {
43 clientManifest?: object
44 serializer?: (state: object) => string
45 runInNewContext?: boolean | 'once'
46 basedir?: string
47}
48
49interface RenderCache {
50 get: (key: string, cb?: (res: string) => void) => string | void
51 set: (key: string, val: string) => void
52 has?: (key: string, cb?: (hit: boolean) => void) => boolean | void
53}