10
0

typings.d.ts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. import { AsyncSeriesWaterfallHook } from "tapable";
  2. import { Compiler, Compilation } from "webpack";
  3. import { Options as HtmlMinifierOptions } from "html-minifier-terser";
  4. export = HtmlWebpackPlugin;
  5. declare class HtmlWebpackPlugin {
  6. constructor(options?: HtmlWebpackPlugin.Options);
  7. userOptions: HtmlWebpackPlugin.Options;
  8. /** Current HtmlWebpackPlugin Major */
  9. version: number;
  10. /**
  11. * Options after html-webpack-plugin has been initialized with defaults
  12. */
  13. options?: HtmlWebpackPlugin.ProcessedOptions;
  14. apply(compiler: Compiler): void;
  15. static getHooks(compilation: Compilation): HtmlWebpackPlugin.Hooks;
  16. static getCompilationHooks(compilation: Compilation): HtmlWebpackPlugin.Hooks;
  17. /**
  18. * Static helper to create a tag object to be get injected into the dom
  19. */
  20. static createHtmlTagObject(
  21. tagName: string,
  22. attributes?: { [attributeName: string]: string | boolean },
  23. innerHTML?: string,
  24. ): HtmlWebpackPlugin.HtmlTagObject;
  25. static readonly version: number;
  26. }
  27. declare namespace HtmlWebpackPlugin {
  28. type MinifyOptions = HtmlMinifierOptions;
  29. interface Options {
  30. /**
  31. * Emit the file only if it was changed.
  32. * @default true
  33. */
  34. cache?: boolean;
  35. /**
  36. * List all entries which should be injected
  37. */
  38. chunks?: "all" | string[];
  39. /**
  40. * Allows to control how chunks should be sorted before they are included to the html.
  41. * @default 'auto'
  42. */
  43. chunksSortMode?:
  44. | "auto"
  45. // `none` is deprecated and an alias for `auto` now.
  46. | "none"
  47. | "manual"
  48. | ((entryNameA: string, entryNameB: string) => number);
  49. /**
  50. * List all entries which should not be injected
  51. */
  52. excludeChunks?: string[];
  53. /**
  54. * Path to the favicon icon
  55. */
  56. favicon?: false | string;
  57. /**
  58. * The file to write the HTML to.
  59. * Supports subdirectories eg: `assets/admin.html`
  60. * [name] will be replaced by the entry name
  61. * Supports a function to generate the name
  62. *
  63. * @default 'index.html'
  64. */
  65. filename?: string | ((entryName: string) => 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 'defer'
  90. */
  91. scriptLoading?: "blocking" | "defer" | "module" | "systemjs-module";
  92. /**
  93. * Inject meta tags
  94. */
  95. meta?:
  96. | false // Disable injection
  97. | {
  98. [name: string]:
  99. | string
  100. | false // name content pair e.g. {viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'}`
  101. | { [attributeName: string]: string | boolean }; // custom properties e.g. { name:"viewport" content:"width=500, initial-scale=1" }
  102. };
  103. /**
  104. * HTML Minification options accepts the following values:
  105. * - Set to `false` to disable minification
  106. * - Set to `'auto'` to enable minification only for production mode
  107. * - Set to custom minification according to
  108. * {@link https://github.com/kangax/html-minifier#options-quick-reference}
  109. */
  110. minify?: "auto" | boolean | MinifyOptions;
  111. /**
  112. * Render errors into the HTML page
  113. */
  114. showErrors?: boolean;
  115. /**
  116. * The `webpack` require path to the template.
  117. * @see https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md
  118. */
  119. template?: string;
  120. /**
  121. * Allow to use a html string instead of reading from a file
  122. */
  123. templateContent?:
  124. | false // Use the template option instead to load a file
  125. | string
  126. | ((templateParameters: {
  127. [option: string]: any;
  128. }) => 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: Compilation,
  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. * The plugin options after adding default values
  167. */
  168. interface ProcessedOptions extends Required<Options> {
  169. filename: string;
  170. }
  171. /**
  172. * The values which are available during template execution
  173. *
  174. * Please keep in mind that the `templateParameter` options allows to change them
  175. */
  176. interface TemplateParameter {
  177. compilation: Compilation;
  178. htmlWebpackPlugin: {
  179. tags: {
  180. headTags: HtmlTagObject[];
  181. bodyTags: HtmlTagObject[];
  182. };
  183. files: {
  184. publicPath: string;
  185. js: Array<string>;
  186. css: Array<string>;
  187. manifest?: string;
  188. favicon?: string;
  189. };
  190. options: Options;
  191. };
  192. webpackConfig: any;
  193. }
  194. interface Hooks {
  195. alterAssetTags: AsyncSeriesWaterfallHook<{
  196. assetTags: {
  197. scripts: HtmlTagObject[];
  198. styles: HtmlTagObject[];
  199. meta: HtmlTagObject[];
  200. };
  201. publicPath: string;
  202. outputName: string;
  203. plugin: HtmlWebpackPlugin;
  204. }>;
  205. alterAssetTagGroups: AsyncSeriesWaterfallHook<{
  206. headTags: HtmlTagObject[];
  207. bodyTags: HtmlTagObject[];
  208. outputName: string;
  209. publicPath: string;
  210. plugin: HtmlWebpackPlugin;
  211. }>;
  212. afterTemplateExecution: AsyncSeriesWaterfallHook<{
  213. html: string;
  214. headTags: HtmlTagObject[];
  215. bodyTags: HtmlTagObject[];
  216. outputName: string;
  217. plugin: HtmlWebpackPlugin;
  218. }>;
  219. beforeAssetTagGeneration: AsyncSeriesWaterfallHook<{
  220. assets: {
  221. publicPath: string;
  222. js: Array<string>;
  223. css: Array<string>;
  224. favicon?: string;
  225. manifest?: string;
  226. };
  227. outputName: string;
  228. plugin: HtmlWebpackPlugin;
  229. }>;
  230. beforeEmit: AsyncSeriesWaterfallHook<{
  231. html: string;
  232. outputName: string;
  233. plugin: HtmlWebpackPlugin;
  234. }>;
  235. afterEmit: AsyncSeriesWaterfallHook<{
  236. outputName: string;
  237. plugin: HtmlWebpackPlugin;
  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 | null | undefined;
  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. * Meta information about the tag
  266. * E.g. `{'plugin': 'html-webpack-plugin'}`
  267. */
  268. meta: {
  269. plugin?: string;
  270. [metaAttributeName: string]: any;
  271. };
  272. }
  273. }