typings.d.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. apply(compiler: Compiler): void;
  8. static getHooks(compilation: compilation.Compilation): HtmlWebpackPlugin.Hooks;
  9. }
  10. declare namespace HtmlWebpackPlugin {
  11. type MinifyOptions = HtmlMinifierOptions;
  12. interface Options extends Partial<ProcessedOptions> {}
  13. /**
  14. * The plugin options after adding default values
  15. */
  16. interface ProcessedOptions {
  17. /**
  18. * Emit the file only if it was changed.
  19. * Default: `true`.
  20. */
  21. cache: boolean;
  22. /**
  23. * List all entries which should be injected
  24. */
  25. chunks: "all" | string[];
  26. /**
  27. * Allows to control how chunks should be sorted before they are included to the html.
  28. * Default: `'auto'`.
  29. */
  30. chunksSortMode:
  31. | "auto"
  32. | "manual"
  33. | (((entryNameA: string, entryNameB: string) => number));
  34. /**
  35. * List all entries which should not be injeccted
  36. */
  37. excludeChunks: string[];
  38. /**
  39. * Path to the favicon icon
  40. */
  41. favicon: false | string;
  42. /**
  43. * The file to write the HTML to.
  44. * Defaults to `index.html`.
  45. * Supports subdirectories eg: `assets/admin.html`
  46. */
  47. filename: string;
  48. /**
  49. * If `true` then append a unique `webpack` compilation hash to all included scripts and CSS files.
  50. * This is useful for cache busting
  51. */
  52. hash: boolean;
  53. /**
  54. * Inject all assets into the given `template` or `templateContent`.
  55. */
  56. inject:
  57. | false // Don't inject scripts
  58. | true // Inject scripts into body
  59. | "body" // Inject scripts into body
  60. | "head" // Inject scripts into head
  61. /**
  62. * Set up script loading
  63. * blocking will result in <script src="..."></script>
  64. * defer will result in <script defer src="..."></script>
  65. *
  66. * The default behaviour is blocking
  67. */
  68. scriptLoading:
  69. | "blocking"
  70. | "defer"
  71. /**
  72. * Inject meta tags
  73. */
  74. meta:
  75. | false // Disable injection
  76. | {
  77. [name: string]:
  78. | string
  79. | false // name content pair e.g. {viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'}`
  80. | { [attributeName: string]: string | boolean }; // custom properties e.g. { name:"viewport" content:"width=500, initial-scale=1" }
  81. };
  82. /**
  83. * HTML Minification options accepts the following valeus:
  84. * - Set to `false` to disable minifcation
  85. * - Set to `'auto'` to enable minifcation only for production mode
  86. * - Set to custom minification according to
  87. * @https://github.com/kangax/html-minifier#options-quick-reference
  88. */
  89. minify: 'auto' | boolean | MinifyOptions;
  90. /**
  91. * Render errors into the HTML page
  92. */
  93. showErrors: boolean;
  94. /**
  95. * The `webpack` require path to the template.
  96. * @see https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md
  97. */
  98. template: string;
  99. /**
  100. * Allow to use a html string instead of reading from a file
  101. */
  102. templateContent:
  103. | false // Use the template option instead to load a file
  104. | string
  105. | Promise<string>;
  106. /**
  107. * Allows to overwrite the parameters used in the template
  108. */
  109. templateParameters:
  110. | false // Pass an empty object to the template function
  111. | ((
  112. compilation: any,
  113. assets: {
  114. publicPath: string;
  115. js: Array<string>;
  116. css: Array<string>;
  117. manifest?: string;
  118. favicon?: string;
  119. },
  120. assetTags: {
  121. headTags: HtmlTagObject[];
  122. bodyTags: HtmlTagObject[];
  123. },
  124. options: ProcessedOptions
  125. ) => { [option: string]: any } | Promise<{ [option: string]: any }>)
  126. | { [option: string]: any };
  127. /**
  128. * The title to use for the generated HTML document
  129. */
  130. title: string;
  131. /**
  132. * Enforce self closing tags e.g. <link />
  133. */
  134. xhtml: boolean;
  135. /**
  136. * In addition to the options actually used by this plugin, you can use this hash to pass arbitrary data through
  137. * to your template.
  138. */
  139. [option: string]: any;
  140. }
  141. /**
  142. * The values which are available during template execution
  143. *
  144. * Please keep in mind that the `templateParameter` options allows to change them
  145. */
  146. interface TemplateParameter {
  147. compilation: any;
  148. htmlWebpackPlugin: {
  149. tags: {
  150. headTags: HtmlTagObject[];
  151. bodyTags: HtmlTagObject[];
  152. };
  153. files: {
  154. publicPath: string;
  155. js: Array<string>;
  156. css: Array<string>;
  157. manifest?: string;
  158. favicon?: string;
  159. };
  160. options: Options;
  161. };
  162. webpackConfig: any;
  163. }
  164. interface Hooks {
  165. alterAssetTags: AsyncSeriesWaterfallHook<{
  166. assetTags: {
  167. scripts: HtmlTagObject[];
  168. styles: HtmlTagObject[];
  169. meta: HtmlTagObject[];
  170. };
  171. outputName: string;
  172. plugin: HtmlWebpackPlugin;
  173. }>;
  174. alterAssetTagGroups: AsyncSeriesWaterfallHook<{
  175. headTags: HtmlTagObject[];
  176. bodyTags: HtmlTagObject[];
  177. outputName: string;
  178. plugin: HtmlWebpackPlugin;
  179. }>;
  180. afterTemplateExecution: AsyncSeriesWaterfallHook<{
  181. html: string;
  182. headTags: HtmlTagObject[];
  183. bodyTags: HtmlTagObject[];
  184. outputName: string;
  185. plugin: HtmlWebpackPlugin;
  186. }>;
  187. beforeAssetTagGeneration: AsyncSeriesWaterfallHook<{
  188. assets: {
  189. publicPath: string;
  190. js: Array<string>;
  191. css: Array<string>;
  192. favicon?: string;
  193. manifest?: string;
  194. };
  195. outputName: string;
  196. plugin: HtmlWebpackPlugin;
  197. }>;
  198. beforeEmit: AsyncSeriesWaterfallHook<{
  199. html: string;
  200. outputName: string;
  201. plugin: HtmlWebpackPlugin;
  202. }>;
  203. afterEmit: AsyncSeriesWaterfallHook<{
  204. outputName: string;
  205. plugin: HtmlWebpackPlugin;
  206. }>;
  207. }
  208. /**
  209. * A tag element according to the htmlWebpackPlugin object notation
  210. */
  211. interface HtmlTagObject {
  212. /**
  213. * Attributes of the html tag
  214. * E.g. `{'disabled': true, 'value': 'demo'}`
  215. */
  216. attributes: {
  217. [attributeName: string]: string | boolean;
  218. };
  219. /**
  220. * The tag name e.g. `'div'`
  221. */
  222. tagName: string;
  223. /**
  224. * The inner HTML
  225. */
  226. innerHTML?: string;
  227. /**
  228. * Whether this html must not contain innerHTML
  229. * @see https://www.w3.org/TR/html5/syntax.html#void-elements
  230. */
  231. voidTag: boolean;
  232. }
  233. }