UNPKG

7.4 kBTypeScriptView Raw
1import { Options as HtmlMinifierOptions } from "html-minifier";
2import { AsyncSeriesWaterfallHook } from "tapable";
3import { compilation, Compiler, Plugin } from "webpack";
4
5export = HtmlWebpackPlugin;
6
7type TemplateFunction = (param: object) => string;
8
9declare class HtmlWebpackPlugin extends Plugin {
10 constructor(options?: HtmlWebpackPlugin.Options);
11
12 apply(compiler: Compiler): void;
13
14 evaluateCompilationResult(
15 compilation: compilation.Compilation,
16 content: string,
17 ): Promise<string | TemplateFunction>;
18
19 executeTemplate(
20 templateFunction: TemplateFunction,
21 chunks: any,
22 assets: any,
23 compilation: compilation.Compilation,
24 ): Promise<string>;
25
26 postProcessHtml(html: string, assets: any, assetTags: any): Promise<string>;
27}
28
29declare namespace HtmlWebpackPlugin {
30 type MinifyOptions = HtmlMinifierOptions;
31
32 interface TemplateParametersAssets {
33 /** The public path */
34 publicPath: string;
35 /** Will contain all js & css files by chunk */
36 chunks: {};
37 /** Will contain all js files */
38 js: string[];
39 /** Will contain all css files */
40 css: string[];
41 /** Will contain a favicon if it exists */
42 favicon?: string | undefined;
43 /** Will contain amn appcache manifest file if it exists */
44 manifest?: string | undefined;
45 }
46
47 interface Options {
48 /**
49 * Emit the file only if it was changed.
50 * Default: `true`.
51 */
52 cache?: boolean | undefined;
53 /**
54 * Allows to control how chunks should be sorted before they are included to the html.
55 * Default: `'auto'`.
56 */
57 chunksSortMode?:
58 | "none"
59 | "auto"
60 | "dependency"
61 | "manual"
62 | ((a: compilation.Chunk, b: compilation.Chunk) => number)
63 | undefined;
64 /**
65 * Allows you to add only some chunks (e.g. only the unit-test chunk).
66 * Default: 'all'.
67 */
68 chunks?: "all" | string[] | undefined;
69 /**
70 * Allows you to skip some chunks (e.g. don't add the unit-test chunk).
71 * Default: `[]`.
72 */
73 excludeChunks?: string[] | undefined;
74 /**
75 * Adds the given favicon path to the output html.
76 * Default: `false`.
77 */
78 favicon?: false | string | undefined;
79 /**
80 * The file to write the HTML to.
81 * You can specify a subdirectory here too (eg: `assets/admin.html`).
82 * Default: `'index.html'`.
83 */
84 filename?: string | undefined;
85 /**
86 * If true then append a unique webpack compilation hash to all included scripts and CSS files.
87 * This is useful for cache busting.
88 * Default: `false`.
89 */
90 hash?: boolean | undefined;
91 /**
92 * Inject all assets into the given template or templateContent.
93 * When passing true or 'body' all javascript resources will be placed at the bottom of the body element.
94 * 'head' will place the scripts in the head element.
95 * Default: `true`.
96 */
97 inject?: "body" | "head" | boolean | undefined;
98 /**
99 * Allows to inject meta-tags, e.g. meta: `{viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'}`.
100 * Default: `{}`.
101 */
102 meta?: false | { [name: string]: any } | undefined;
103 /**
104 * Pass a html-minifier options object to minify the output.
105 * https://github.com/kangax/html-minifier#options-quick-reference
106 * Default: `false`.
107 */
108 minify?: false | MinifyOptions | undefined;
109 /**
110 * Errors details will be written into the HTML page.
111 * Default: `true`.
112 */
113 showErrors?: boolean | undefined;
114 /**
115 * The `webpack` require path to the template.
116 * @see https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md
117 */
118 template?: string | undefined;
119 /**
120 * Allow to use a html string instead of reading from a file.
121 * Default: `false`, meaning the `template` option should be used instead.
122 */
123 templateContent?: false | string | TemplateFunction | undefined;
124 /**
125 * Allows to overwrite the parameters used in the template.
126 */
127 templateParameters?:
128 | false
129 | ((compilation: compilation.Compilation, assets: TemplateParametersAssets, options: Options) => any)
130 | { [key: string]: any }
131 | undefined;
132 /**
133 * The title to use for the generated HTML document.
134 * Default: `'Webpack App'`.
135 */
136 title?: string | undefined;
137 /**
138 * If true render the link tags as self-closing (XHTML compliant).
139 * Default: `false`.
140 */
141 xhtml?: boolean | undefined;
142 /**
143 * In addition to the options actually used by this plugin, you can use this hash to pass arbitrary data through
144 * to your template.
145 */
146 [option: string]: any;
147 }
148
149 interface Hooks extends compilation.CompilationHooks {
150 htmlWebpackPluginBeforeHtmlGeneration: AsyncSeriesWaterfallHook<{
151 assets: {
152 publicPath: string;
153 js: EntryObject[];
154 css: EntryObject[];
155 };
156 outputName: string;
157 plugin: HtmlWebpackPlugin;
158 }>;
159 htmlWebpackPluginBeforeHtmlProcessing: AsyncSeriesWaterfallHook<{
160 html: string;
161 assets: {
162 publicPath: string;
163 js: EntryObject[];
164 css: EntryObject[];
165 };
166 outputName: string;
167 plugin: HtmlWebpackPlugin;
168 }>;
169 htmlWebpackPluginAfterHtmlProcessing: AsyncSeriesWaterfallHook<{
170 html: string;
171 assets: {
172 publicPath: string;
173 js: EntryObject[];
174 css: EntryObject[];
175 };
176 outputName: string;
177 plugin: HtmlWebpackPlugin;
178 }>;
179 htmlWebpackPluginAlterAssetTags: AsyncSeriesWaterfallHook<{
180 head: HtmlTagObject[];
181 body: HtmlTagObject[];
182 outputName: string;
183 plugin: HtmlWebpackPlugin;
184 }>;
185 htmlWebpackPluginAfterEmit: AsyncSeriesWaterfallHook<{
186 html: string;
187 outputName: string;
188 plugin: HtmlWebpackPlugin;
189 }>;
190 }
191
192 /** @deprecated use MinifyOptions */
193 type MinifyConfig = MinifyOptions;
194 /** @deprecated use Options */
195 type Config = Options;
196}
197
198interface EntryObject {
199 /** Webpack entry or chunk name */
200 entryName: string;
201 /** Entry or chunk path */
202 path: string;
203}
204
205interface HtmlTagObject {
206 /**
207 * Attributes of the html tag
208 * E.g. `{'disabled': true, 'value': 'demo'}`
209 */
210 attributes: {
211 [attributeName: string]: string | boolean;
212 };
213 /**
214 * Wether this html must not contain innerHTML
215 * @see https://www.w3.org/TR/html5/syntax.html#void-elements
216 */
217 voidTag: boolean;
218 /**
219 * The tag name e.g. `'div'`
220 */
221 tagName: string;
222 /**
223 * Inner HTML The
224 */
225 innerHTML?: string | undefined;
226}
227
\No newline at end of file