UNPKG

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