1 | import { AsyncSeriesWaterfallHook } from "tapable";
|
2 | import { Compiler, Compilation } from "webpack";
|
3 | import { Options as HtmlMinifierOptions } from "html-minifier-terser";
|
4 |
|
5 | export = HtmlWebpackPlugin;
|
6 |
|
7 | declare class HtmlWebpackPlugin {
|
8 | constructor(options?: HtmlWebpackPlugin.Options);
|
9 |
|
10 | userOptions: HtmlWebpackPlugin.Options;
|
11 |
|
12 | /** Current HtmlWebpackPlugin Major */
|
13 | version: number;
|
14 |
|
15 | /**
|
16 | * Options after html-webpack-plugin has been initialized with defaults
|
17 | */
|
18 | options?: HtmlWebpackPlugin.ProcessedOptions;
|
19 |
|
20 | apply(compiler: Compiler): void;
|
21 |
|
22 | static getHooks(compilation: Compilation): HtmlWebpackPlugin.Hooks;
|
23 |
|
24 | /**
|
25 | * Static helper to create a tag object to be get injected into the dom
|
26 | */
|
27 | static createHtmlTagObject(
|
28 | tagName: string,
|
29 | attributes?: { [attributeName: string]: string | boolean },
|
30 | innerHTML?: string
|
31 | ): HtmlWebpackPlugin.HtmlTagObject;
|
32 |
|
33 | static readonly version: number;
|
34 | }
|
35 |
|
36 | declare namespace HtmlWebpackPlugin {
|
37 | type MinifyOptions = HtmlMinifierOptions;
|
38 |
|
39 | interface Options {
|
40 | |
41 |
|
42 |
|
43 |
|
44 | cache?: boolean;
|
45 | |
46 |
|
47 |
|
48 | chunks?: "all" | string[];
|
49 | |
50 |
|
51 |
|
52 |
|
53 | chunksSortMode?:
|
54 | | "auto"
|
55 | | "manual"
|
56 | | ((entryNameA: string, entryNameB: string) => number);
|
57 | /**
|
58 | * List all entries which should not be injected
|
59 | */
|
60 | excludeChunks?: string[];
|
61 | /**
|
62 | * Path to the favicon icon
|
63 | */
|
64 | favicon?: false | string;
|
65 | /**
|
66 | * The file to write the HTML to.
|
67 | * Supports subdirectories eg: `assets/admin.html`
|
68 | * [name] will be replaced by the entry name
|
69 | * Supports a function to generate the name
|
70 | *
|
71 | * @default 'index.html'
|
72 | */
|
73 | filename?: string | ((entryName: string) => string);
|
74 | /**
|
75 | * By default the public path is set to `auto` - that way the html-webpack-plugin will try
|
76 | * to set the publicPath according to the current filename and the webpack publicPath setting
|
77 | */
|
78 | publicPath?: string | "auto";
|
79 | /**
|
80 | * If `true` then append a unique `webpack` compilation hash to all included scripts and CSS files.
|
81 | * This is useful for cache busting
|
82 | */
|
83 | hash?: boolean;
|
84 | /**
|
85 | * Inject all assets into the given `template` or `templateContent`.
|
86 | */
|
87 | inject?:
|
88 | | false // Don't inject scripts
|
89 | | true // Inject scripts into body
|
90 | | "body" // Inject scripts into body
|
91 | | "head"; // Inject scripts into head
|
92 | /**
|
93 | * Set up script loading
|
94 | * blocking will result in <script src="..."></script>
|
95 | * defer will result in <script defer src="..."></script>
|
96 | *
|
97 | * @default 'defer'
|
98 | */
|
99 | scriptLoading?: "blocking" | "defer";
|
100 | /**
|
101 | * Inject meta tags
|
102 | */
|
103 | meta?:
|
104 | | false // Disable injection
|
105 | | {
|
106 | [name: string]:
|
107 | | string
|
108 | | false // name content pair e.g. {viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'}`
|
109 | | { [attributeName: string]: string | boolean }; // custom properties e.g. { name:"viewport" content:"width=500, initial-scale=1" }
|
110 | };
|
111 | /**
|
112 | * HTML Minification options accepts the following values:
|
113 | * - Set to `false` to disable minifcation
|
114 | * - Set to `'auto'` to enable minifcation only for production mode
|
115 | * - Set to custom minification according to
|
116 | * {@link https://github.com/kangax/html-minifier#options-quick-reference}
|
117 | */
|
118 | minify?: "auto" | boolean | MinifyOptions;
|
119 | /**
|
120 | * Render errors into the HTML page
|
121 | */
|
122 | showErrors?: boolean;
|
123 | /**
|
124 | * The `webpack` require path to the template.
|
125 | * @see https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md
|
126 | */
|
127 | template?: string;
|
128 | /**
|
129 | * Allow to use a html string instead of reading from a file
|
130 | */
|
131 | templateContent?:
|
132 | | false // Use the template option instead to load a file
|
133 | | string
|
134 | | ((templateParameters: {
|
135 | [option: string]: any;
|
136 | }) => string | Promise<string>)
|
137 | | Promise<string>;
|
138 | /**
|
139 | * Allows to overwrite the parameters used in the template
|
140 | */
|
141 | templateParameters?:
|
142 | | false // Pass an empty object to the template function
|
143 | | ((
|
144 | compilation: any,
|
145 | assets: {
|
146 | publicPath: string;
|
147 | js: Array<string>;
|
148 | css: Array<string>;
|
149 | manifest?: string;
|
150 | favicon?: string;
|
151 | },
|
152 | assetTags: {
|
153 | headTags: HtmlTagObject[];
|
154 | bodyTags: HtmlTagObject[];
|
155 | },
|
156 | options: ProcessedOptions
|
157 | ) => { [option: string]: any } | Promise<{ [option: string]: any }>)
|
158 | | { [option: string]: any };
|
159 | /**
|
160 | * The title to use for the generated HTML document
|
161 | */
|
162 | title?: string;
|
163 | /**
|
164 | * Enforce self closing tags e.g. <link />
|
165 | */
|
166 | xhtml?: boolean;
|
167 | /**
|
168 | * In addition to the options actually used by this plugin, you can use this hash to pass arbitrary data through
|
169 | * to your template.
|
170 | */
|
171 | [option: string]: any;
|
172 | }
|
173 |
|
174 | /**
|
175 | * The plugin options after adding default values
|
176 | */
|
177 | interface ProcessedOptions extends Required<Options> {
|
178 | filename: string;
|
179 | }
|
180 |
|
181 | /**
|
182 | * The values which are available during template execution
|
183 | *
|
184 | * Please keep in mind that the `templateParameter` options allows to change them
|
185 | */
|
186 | interface TemplateParameter {
|
187 | compilation: any;
|
188 | htmlWebpackPlugin: {
|
189 | tags: {
|
190 | headTags: HtmlTagObject[];
|
191 | bodyTags: HtmlTagObject[];
|
192 | };
|
193 | files: {
|
194 | publicPath: string;
|
195 | js: Array<string>;
|
196 | css: Array<string>;
|
197 | manifest?: string;
|
198 | favicon?: string;
|
199 | };
|
200 | options: Options;
|
201 | };
|
202 | webpackConfig: any;
|
203 | }
|
204 |
|
205 | interface Hooks {
|
206 | alterAssetTags: AsyncSeriesWaterfallHook<{
|
207 | assetTags: {
|
208 | scripts: HtmlTagObject[];
|
209 | styles: HtmlTagObject[];
|
210 | meta: HtmlTagObject[];
|
211 | };
|
212 | publicPath: string,
|
213 | outputName: string;
|
214 | plugin: HtmlWebpackPlugin;
|
215 | }>;
|
216 |
|
217 | alterAssetTagGroups: AsyncSeriesWaterfallHook<{
|
218 | headTags: HtmlTagObject[];
|
219 | bodyTags: HtmlTagObject[];
|
220 | outputName: string;
|
221 | publicPath: string,
|
222 | plugin: HtmlWebpackPlugin;
|
223 | }>;
|
224 |
|
225 | afterTemplateExecution: AsyncSeriesWaterfallHook<{
|
226 | html: string;
|
227 | headTags: HtmlTagObject[];
|
228 | bodyTags: HtmlTagObject[];
|
229 | outputName: string;
|
230 | plugin: HtmlWebpackPlugin;
|
231 | }>;
|
232 |
|
233 | beforeAssetTagGeneration: AsyncSeriesWaterfallHook<{
|
234 | assets: {
|
235 | publicPath: string;
|
236 | js: Array<string>;
|
237 | css: Array<string>;
|
238 | favicon?: string;
|
239 | manifest?: string;
|
240 | };
|
241 | outputName: string;
|
242 | plugin: HtmlWebpackPlugin;
|
243 | }>;
|
244 |
|
245 | beforeEmit: AsyncSeriesWaterfallHook<{
|
246 | html: string;
|
247 | outputName: string;
|
248 | plugin: HtmlWebpackPlugin;
|
249 | }>;
|
250 |
|
251 | afterEmit: AsyncSeriesWaterfallHook<{
|
252 | outputName: string;
|
253 | plugin: HtmlWebpackPlugin;
|
254 | }>;
|
255 | }
|
256 |
|
257 | /**
|
258 | * A tag element according to the htmlWebpackPlugin object notation
|
259 | */
|
260 | interface HtmlTagObject {
|
261 | /**
|
262 | * Attributes of the html tag
|
263 | * E.g. `{'disabled': true, 'value': 'demo'}`
|
264 | */
|
265 | attributes: {
|
266 | [attributeName: string]: string | boolean | null | undefined;
|
267 | };
|
268 | /**
|
269 | * The tag name e.g. `'div'`
|
270 | */
|
271 | tagName: string;
|
272 | /**
|
273 | * The inner HTML
|
274 | */
|
275 | innerHTML?: string;
|
276 | /**
|
277 | * Whether this html must not contain innerHTML
|
278 | * @see https://www.w3.org/TR/html5/syntax.html#void-elements
|
279 | */
|
280 | voidTag: boolean;
|
281 | /**
|
282 | * Meta information about the tag
|
283 | * E.g. `{'plugin': 'html-webpack-plugin'}`
|
284 | */
|
285 | meta: {
|
286 | plugin?: string,
|
287 | [metaAttributeName: string]: any;
|
288 | };
|
289 | }
|
290 | }
|
291 |
|
\ | No newline at end of file |