typings.d.ts
7.83 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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
import { AsyncSeriesWaterfallHook } from "tapable";
import { Compiler, Compilation } from "webpack";
import { Options as HtmlMinifierOptions } from "html-minifier-terser";
export = HtmlWebpackPlugin;
declare class HtmlWebpackPlugin {
constructor(options?: HtmlWebpackPlugin.Options);
userOptions: HtmlWebpackPlugin.Options;
/** Current HtmlWebpackPlugin Major */
version: number;
/**
* Options after html-webpack-plugin has been initialized with defaults
*/
options?: HtmlWebpackPlugin.ProcessedOptions;
apply(compiler: Compiler): void;
static getHooks(compilation: Compilation): HtmlWebpackPlugin.Hooks;
/**
* Static helper to create a tag object to be get injected into the dom
*/
static createHtmlTagObject(
tagName: string,
attributes?: { [attributeName: string]: string | boolean },
innerHTML?: string
): HtmlWebpackPlugin.HtmlTagObject;
static readonly version: number;
}
declare namespace HtmlWebpackPlugin {
type MinifyOptions = HtmlMinifierOptions;
interface Options {
/**
* Emit the file only if it was changed.
* @default true
*/
cache?: boolean;
/**
* List all entries which should be injected
*/
chunks?: "all" | string[];
/**
* Allows to control how chunks should be sorted before they are included to the html.
* @default 'auto'
*/
chunksSortMode?:
| "auto"
| "manual"
| ((entryNameA: string, entryNameB: string) => number);
/**
* List all entries which should not be injected
*/
excludeChunks?: string[];
/**
* Path to the favicon icon
*/
favicon?: false | string;
/**
* The file to write the HTML to.
* Supports subdirectories eg: `assets/admin.html`
* [name] will be replaced by the entry name
* Supports a function to generate the name
*
* @default 'index.html'
*/
filename?: string | ((entryName: string) => string);
/**
* By default the public path is set to `auto` - that way the html-webpack-plugin will try
* to set the publicPath according to the current filename and the webpack publicPath setting
*/
publicPath?: string | "auto";
/**
* If `true` then append a unique `webpack` compilation hash to all included scripts and CSS files.
* This is useful for cache busting
*/
hash?: boolean;
/**
* Inject all assets into the given `template` or `templateContent`.
*/
inject?:
| false // Don't inject scripts
| true // Inject scripts into body
| "body" // Inject scripts into body
| "head"; // Inject scripts into head
/**
* Set up script loading
* blocking will result in <script src="..."></script>
* defer will result in <script defer src="..."></script>
*
* @default 'defer'
*/
scriptLoading?: "blocking" | "defer" | "module";
/**
* Inject meta tags
*/
meta?:
| false // Disable injection
| {
[name: string]:
| string
| false // name content pair e.g. {viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'}`
| { [attributeName: string]: string | boolean }; // custom properties e.g. { name:"viewport" content:"width=500, initial-scale=1" }
};
/**
* HTML Minification options accepts the following values:
* - Set to `false` to disable minifcation
* - Set to `'auto'` to enable minifcation only for production mode
* - Set to custom minification according to
* {@link https://github.com/kangax/html-minifier#options-quick-reference}
*/
minify?: "auto" | boolean | MinifyOptions;
/**
* Render errors into the HTML page
*/
showErrors?: boolean;
/**
* The `webpack` require path to the template.
* @see https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md
*/
template?: string;
/**
* Allow to use a html string instead of reading from a file
*/
templateContent?:
| false // Use the template option instead to load a file
| string
| ((templateParameters: {
[option: string]: any;
}) => string | Promise<string>)
| Promise<string>;
/**
* Allows to overwrite the parameters used in the template
*/
templateParameters?:
| false // Pass an empty object to the template function
| ((
compilation: any,
assets: {
publicPath: string;
js: Array<string>;
css: Array<string>;
manifest?: string;
favicon?: string;
},
assetTags: {
headTags: HtmlTagObject[];
bodyTags: HtmlTagObject[];
},
options: ProcessedOptions
) => { [option: string]: any } | Promise<{ [option: string]: any }>)
| { [option: string]: any };
/**
* The title to use for the generated HTML document
*/
title?: string;
/**
* Enforce self closing tags e.g. <link />
*/
xhtml?: boolean;
/**
* In addition to the options actually used by this plugin, you can use this hash to pass arbitrary data through
* to your template.
*/
[option: string]: any;
}
/**
* The plugin options after adding default values
*/
interface ProcessedOptions extends Required<Options> {
filename: string;
}
/**
* The values which are available during template execution
*
* Please keep in mind that the `templateParameter` options allows to change them
*/
interface TemplateParameter {
compilation: any;
htmlWebpackPlugin: {
tags: {
headTags: HtmlTagObject[];
bodyTags: HtmlTagObject[];
};
files: {
publicPath: string;
js: Array<string>;
css: Array<string>;
manifest?: string;
favicon?: string;
};
options: Options;
};
webpackConfig: any;
}
interface Hooks {
alterAssetTags: AsyncSeriesWaterfallHook<{
assetTags: {
scripts: HtmlTagObject[];
styles: HtmlTagObject[];
meta: HtmlTagObject[];
};
publicPath: string,
outputName: string;
plugin: HtmlWebpackPlugin;
}>;
alterAssetTagGroups: AsyncSeriesWaterfallHook<{
headTags: HtmlTagObject[];
bodyTags: HtmlTagObject[];
outputName: string;
publicPath: string,
plugin: HtmlWebpackPlugin;
}>;
afterTemplateExecution: AsyncSeriesWaterfallHook<{
html: string;
headTags: HtmlTagObject[];
bodyTags: HtmlTagObject[];
outputName: string;
plugin: HtmlWebpackPlugin;
}>;
beforeAssetTagGeneration: AsyncSeriesWaterfallHook<{
assets: {
publicPath: string;
js: Array<string>;
css: Array<string>;
favicon?: string;
manifest?: string;
};
outputName: string;
plugin: HtmlWebpackPlugin;
}>;
beforeEmit: AsyncSeriesWaterfallHook<{
html: string;
outputName: string;
plugin: HtmlWebpackPlugin;
}>;
afterEmit: AsyncSeriesWaterfallHook<{
outputName: string;
plugin: HtmlWebpackPlugin;
}>;
}
/**
* A tag element according to the htmlWebpackPlugin object notation
*/
interface HtmlTagObject {
/**
* Attributes of the html tag
* E.g. `{'disabled': true, 'value': 'demo'}`
*/
attributes: {
[attributeName: string]: string | boolean | null | undefined;
};
/**
* The tag name e.g. `'div'`
*/
tagName: string;
/**
* The inner HTML
*/
innerHTML?: string;
/**
* Whether this html must not contain innerHTML
* @see https://www.w3.org/TR/html5/syntax.html#void-elements
*/
voidTag: boolean;
/**
* Meta information about the tag
* E.g. `{'plugin': 'html-webpack-plugin'}`
*/
meta: {
plugin?: string,
[metaAttributeName: string]: any;
};
}
}