-
-
Notifications
You must be signed in to change notification settings - Fork 128
/
types.ts
152 lines (132 loc) · 3.81 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* eslint-disable no-use-before-define */
import type { App } from 'vue'
import type { RouteRecordRaw, Router, 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'
/**
* Built format
*
* @default 'esm'
*/
format?: 'esm' | 'cjs'
/**
* 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 environment mode
*/
mode?: string
/**
* Directory style of the output directory.
*
* flat: `/foo` -> `/foo.html`
* nested: `/foo` -> `/foo/index.html`
*
* @default flat
*/
dirStyle?: 'flat' | 'nested'
/**
* Generate for all routes, including dynamic routes.
* If enabled, you will need to configure your server
* manually to handle dynamic routes properly.
*
* @default false
*/
includeAllRoutes?: boolean
/**
* Options for critters
*
* @see https://github.com/GoogleChromeLabs/critters
*/
crittersOptions?: CrittersOptions | false
/**
* Custom functions to modified the routes to do the SSG.
*
* Works only when `includeAllRoutes` is set to false.
*
* 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?: (paths: string[], routes: RouteRecordRaw[]) => Promise<string[]> | 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, appCtx: ViteSSGContext<true>) => Promise<string | null | undefined> | 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, appCtx: ViteSSGContext<true>) => Promise<string | null | undefined> | string | null | undefined
onFinished?: () => Promise<void> | void
/**
* The app root container `id`.
*
* @default `app`
*/
rootContainerId?: string
/**
* Size of generation processing queue.
*
* @default 20
*/
concurrency?: number
}
type PartialKeys<T, Keys extends keyof T> = Omit<T, Keys> & Partial<Pick<T, Keys>>
export interface ViteSSGContext<HasRouter extends boolean = true> {
app: App<Element>
router: HasRouter extends true ? Router : undefined
routes: HasRouter extends true ? RouteRecordRaw[] : undefined
initialState: Record<string, any>
head: HeadClient | undefined
isClient: boolean
onSSRAppRendered(cb: Function): void
triggerOnSSRAppRendered(route: string, appHTML: string, appCtx: ViteSSGContext): Promise<unknown[]>
transformState?(state: any): any
/**
* Current router path on SSG, `undefined` on client side.
*/
routePath?: string
}
export interface ViteSSGClientOptions {
transformState?: (state: any) => any
registerComponents?: boolean
useHead?: boolean
/**
* The app root container query selector.
*
* @default `#app`
*/
rootContainer?: string | Element
}
export type RouterOptions = PartialKeys<VueRouterOptions, 'history'> & { base?: string }
// extend vite.config.ts
declare module 'vite' {
interface UserConfig {
ssgOptions?: ViteSSGOptions
}
}