UNPKG

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