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