UNPKG

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