@@ -2,13 +2,6 @@ import { Plugin } from "webpack";
2
2
import { AsyncSeriesWaterfallHook } from "tapable" ;
3
3
import { Options as HtmlMinifierOptions } from "html-minifier" ;
4
4
5
- // https://github.com/Microsoft/TypeScript/issues/15012#issuecomment-365453623
6
- type Required < T > = T extends object
7
- ? { [ P in keyof T ] -?: NonNullable < T [ P ] > }
8
- : T ;
9
- // https://stackoverflow.com/questions/48215950/exclude-property-from-type
10
- type Omit < T , K extends keyof T > = Pick < T , Exclude < keyof T , K > > ;
11
-
12
5
export = HtmlWebpackPlugin ;
13
6
14
7
declare class HtmlWebpackPlugin extends Plugin {
@@ -18,58 +11,60 @@ declare class HtmlWebpackPlugin extends Plugin {
18
11
declare namespace HtmlWebpackPlugin {
19
12
type MinifyOptions = HtmlMinifierOptions ;
20
13
14
+ interface Options extends Partial < ProcessedOptions > { }
15
+
21
16
/**
22
- * The plugin options
17
+ * The plugin options after adding default values
23
18
*/
24
- interface Options {
19
+ interface ProcessedOptions {
25
20
/**
26
21
* Emit the file only if it was changed.
27
22
* Default: `true`.
28
23
*/
29
- cache ? : boolean ;
24
+ cache : boolean ;
30
25
/**
31
26
* List all entries which should be injected
32
27
*/
33
- chunks ? : "all" | string [ ] ;
28
+ chunks : "all" | string [ ] ;
34
29
/**
35
30
* Allows to control how chunks should be sorted before they are included to the html.
36
31
* Default: `'auto'`.
37
32
*/
38
- chunksSortMode ? :
33
+ chunksSortMode :
39
34
| "auto"
40
35
| "manual"
41
36
| ( ( ( entryNameA : string , entryNameB : string ) => number ) ) ;
42
37
/**
43
38
* List all entries which should not be injeccted
44
39
*/
45
- excludeChunks ? : string [ ] ;
40
+ excludeChunks : string [ ] ;
46
41
/**
47
42
* Path to the favicon icon
48
43
*/
49
- favicon ? : false | string ;
44
+ favicon : false | string ;
50
45
/**
51
46
* The file to write the HTML to.
52
47
* Defaults to `index.html`.
53
48
* Supports subdirectories eg: `assets/admin.html`
54
49
*/
55
- filename ? : string ;
50
+ filename : string ;
56
51
/**
57
52
* If `true` then append a unique `webpack` compilation hash to all included scripts and CSS files.
58
53
* This is useful for cache busting
59
54
*/
60
- hash ? : boolean ;
55
+ hash : boolean ;
61
56
/**
62
57
* Inject all assets into the given `template` or `templateContent`.
63
58
*/
64
- inject ? :
59
+ inject :
65
60
| false // Don't inject scripts
66
61
| true // Inject scripts into body
67
62
| "body" // Inject scripts into body
68
63
| "head" ; // Inject scripts into head
69
64
/**
70
65
* Inject meta tags
71
66
*/
72
- meta ? :
67
+ meta :
73
68
| false // Disable injection
74
69
| {
75
70
[ name : string ] :
@@ -78,30 +73,33 @@ declare namespace HtmlWebpackPlugin {
78
73
| { [ attributeName : string ] : string | boolean } ; // custom properties e.g. { name:"viewport" content:"width=500, initial-scale=1" }
79
74
} ;
80
75
/**
81
- * HTML Minification options
76
+ * HTML Minification options accepts the following valeus:
77
+ * - Set to `false` to disable minifcation
78
+ * - Set to `'auto'` to enable minifcation only for production mode
79
+ * - Set to custom minification according to
82
80
* @https ://github.com/kangax/html-minifier#options-quick-reference
83
81
*/
84
- minify ?: boolean | MinifyOptions ;
82
+ minify : 'auto' | boolean | MinifyOptions ;
85
83
/**
86
84
* Render errors into the HTML page
87
85
*/
88
- showErrors ? : boolean ;
86
+ showErrors : boolean ;
89
87
/**
90
88
* The `webpack` require path to the template.
91
89
* @see https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md
92
90
*/
93
- template ? : string ;
91
+ template : string ;
94
92
/**
95
93
* Allow to use a html string instead of reading from a file
96
94
*/
97
- templateContent ? :
95
+ templateContent :
98
96
| false // Use the template option instead to load a file
99
97
| string
100
98
| Promise < string > ;
101
99
/**
102
100
* Allows to overwrite the parameters used in the template
103
101
*/
104
- templateParameters ? :
102
+ templateParameters :
105
103
| false // Pass an empty object to the template function
106
104
| ( (
107
105
compilation : any ,
@@ -110,7 +108,7 @@ declare namespace HtmlWebpackPlugin {
110
108
headTags : HtmlTagObject [ ] ;
111
109
bodyTags : HtmlTagObject [ ] ;
112
110
} ,
113
- options : Options
111
+ options : ProcessedOptions
114
112
) => { [ option : string ] : any } )
115
113
| ( (
116
114
compilation : any ,
@@ -119,37 +117,24 @@ declare namespace HtmlWebpackPlugin {
119
117
headTags : HtmlTagObject [ ] ;
120
118
bodyTags : HtmlTagObject [ ] ;
121
119
} ,
122
- options : Options
120
+ options : ProcessedOptions
123
121
) => Promise < { [ option : string ] : any } > )
124
122
| { [ option : string ] : any } ;
125
123
/**
126
124
* The title to use for the generated HTML document
127
125
*/
128
- title ? : string ;
126
+ title : string ;
129
127
/**
130
128
* Enforce self closing tags e.g. <link />
131
129
*/
132
- xhtml ? : boolean ;
130
+ xhtml : boolean ;
133
131
/**
134
132
* In addition to the options actually used by this plugin, you can use this hash to pass arbitrary data through
135
133
* to your template.
136
134
*/
137
135
[ option : string ] : any ;
138
136
}
139
137
140
- /**
141
- * Options interface that matches the expectations of the index.js API:
142
- * - All fields are required
143
- * - The minify property matches what html-minifier expects (eg either a MinifyOptions or undefined).
144
- * html-minifier does not accept a boolean value. As TypeScript does not allow a property to be redefined
145
- * in an extended interface we need to omit it and then define it properly
146
- *
147
- * The Required and Omit types are defined at the top of the file
148
- */
149
- interface ProcessedOptions extends Required < Omit < Options , "minify" > > {
150
- minify : MinifyOptions | undefined ;
151
- }
152
-
153
138
/**
154
139
* The values which are available during template execution
155
140
*
0 commit comments