-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtypes.ts
More file actions
90 lines (82 loc) · 1.96 KB
/
types.ts
File metadata and controls
90 lines (82 loc) · 1.96 KB
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
import { type IncomingMessage } from 'http'
export type PageObject = {
template: string,
data?: VirtualHtmlTemplateData,
render?: VirtualHtmlTemplateRender,
}
/**
* describe a page
*/
export type VirtualHtmlPage = string | PageObject | VirtualPageOptions
/**
* html template render
*/
export type VirtualHtmlTemplateRender = (template: string, data: Record<string, any>, htmlName?: string) => string
export type VirtualHtmlTemplateData = Record<string, any>
export type Pages = {
[key: string]: VirtualHtmlPage
}
export type VirtualPageOptions = {
entry: string,
title?: string,
body?: string,
}
export type UrlTransformerFunction = (resolvedUrl: string, req: IncomingMessage) => string
/**
* plugin config options
*/
export type HtmlPluginOptions = {
/**
* config html-entries' path
* if it is true, plugin will use glob to find all the html page in project to generate a json like {a: /src/a/a.html,}
*/
pages?: Pages | true,
/**
* transform url to another url by user.
* This is ONLY apply in dev mode.
* @param url
*/
urlTransformer?: UrlTransformerFunction
/**
* define the index page,to replace default index.html
* this page will trigger `transformIndexHtml` hook.
*/
indexPage?: string,
/**
* use for template. as global inject data
*/
data?: Record<string, unknown>
/**
* function to render template
*/
render?: VirtualHtmlTemplateRender
/**
* when pages set to true, customize fast-glob's pattern
* default value is ['**\\*.html', '!node_modules\\**\\*.html', '!.**\\*.html']
*/
extraGlobPattern?: Array<string>
/**
* inject code to html
* key: html name, can be *
*/
injectCode?: Record<string, InjectCode>
/**
* is set appType to custom?
*/
useCustom?: boolean
cwd?: string
}
/**
* inject code to tag's before or after
*/
export enum POS {
before, after
}
/**
* inject code config
*/
export type InjectCode = {
pos: POS,
find: string,
replacement: string,
}