UNPKG

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