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