typings.d.ts 7.2 KB

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