123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- import { AsyncSeriesWaterfallHook } from "tapable";
- import { Compiler, compilation } from 'webpack';
- import { Options as HtmlMinifierOptions } from "html-minifier-terser";
- export = HtmlWebpackPlugin;
- declare class HtmlWebpackPlugin {
- constructor(options?: HtmlWebpackPlugin.Options);
- apply(compiler: Compiler): void;
- static getHooks(compilation: compilation.Compilation): HtmlWebpackPlugin.Hooks;
- }
- declare namespace HtmlWebpackPlugin {
- type MinifyOptions = HtmlMinifierOptions;
- interface Options extends Partial<ProcessedOptions> {}
- /**
- * The plugin options after adding default values
- */
- interface ProcessedOptions {
- /**
- * Emit the file only if it was changed.
- * Default: `true`.
- */
- cache: boolean;
- /**
- * List all entries which should be injected
- */
- chunks: "all" | string[];
- /**
- * Allows to control how chunks should be sorted before they are included to the html.
- * Default: `'auto'`.
- */
- chunksSortMode:
- | "auto"
- | "manual"
- | (((entryNameA: string, entryNameB: string) => number));
- /**
- * List all entries which should not be injeccted
- */
- excludeChunks: string[];
- /**
- * Path to the favicon icon
- */
- favicon: false | string;
- /**
- * The file to write the HTML to.
- * Defaults to `index.html`.
- * Supports subdirectories eg: `assets/admin.html`
- */
- filename: string;
- /**
- * If `true` then append a unique `webpack` compilation hash to all included scripts and CSS files.
- * This is useful for cache busting
- */
- hash: boolean;
- /**
- * Inject all assets into the given `template` or `templateContent`.
- */
- inject:
- | false // Don't inject scripts
- | true // Inject scripts into body
- | "body" // Inject scripts into body
- | "head" // Inject scripts into head
- /**
- * Set up script loading
- * blocking will result in <script src="..."></script>
- * defer will result in <script defer src="..."></script>
- *
- * The default behaviour is blocking
- */
- scriptLoading:
- | "blocking"
- | "defer"
- /**
- * Inject meta tags
- */
- meta:
- | false // Disable injection
- | {
- [name: string]:
- | string
- | false // name content pair e.g. {viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'}`
- | { [attributeName: string]: string | boolean }; // custom properties e.g. { name:"viewport" content:"width=500, initial-scale=1" }
- };
- /**
- * HTML Minification options accepts the following valeus:
- * - Set to `false` to disable minifcation
- * - Set to `'auto'` to enable minifcation only for production mode
- * - Set to custom minification according to
- * @https://github.com/kangax/html-minifier#options-quick-reference
- */
- minify: 'auto' | boolean | MinifyOptions;
- /**
- * Render errors into the HTML page
- */
- showErrors: boolean;
- /**
- * The `webpack` require path to the template.
- * @see https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md
- */
- template: string;
- /**
- * Allow to use a html string instead of reading from a file
- */
- templateContent:
- | false // Use the template option instead to load a file
- | string
- | Promise<string>;
- /**
- * Allows to overwrite the parameters used in the template
- */
- templateParameters:
- | false // Pass an empty object to the template function
- | ((
- compilation: any,
- assets: {
- publicPath: string;
- js: Array<string>;
- css: Array<string>;
- manifest?: string;
- favicon?: string;
- },
- assetTags: {
- headTags: HtmlTagObject[];
- bodyTags: HtmlTagObject[];
- },
- options: ProcessedOptions
- ) => { [option: string]: any } | Promise<{ [option: string]: any }>)
- | { [option: string]: any };
- /**
- * The title to use for the generated HTML document
- */
- title: string;
- /**
- * Enforce self closing tags e.g. <link />
- */
- xhtml: boolean;
- /**
- * In addition to the options actually used by this plugin, you can use this hash to pass arbitrary data through
- * to your template.
- */
- [option: string]: any;
- }
- /**
- * The values which are available during template execution
- *
- * Please keep in mind that the `templateParameter` options allows to change them
- */
- interface TemplateParameter {
- compilation: any;
- htmlWebpackPlugin: {
- tags: {
- headTags: HtmlTagObject[];
- bodyTags: HtmlTagObject[];
- };
- files: {
- publicPath: string;
- js: Array<string>;
- css: Array<string>;
- manifest?: string;
- favicon?: string;
- };
- options: Options;
- };
- webpackConfig: any;
- }
- interface Hooks {
- alterAssetTags: AsyncSeriesWaterfallHook<{
- assetTags: {
- scripts: HtmlTagObject[];
- styles: HtmlTagObject[];
- meta: HtmlTagObject[];
- };
- outputName: string;
- plugin: HtmlWebpackPlugin;
- }>;
- alterAssetTagGroups: AsyncSeriesWaterfallHook<{
- headTags: HtmlTagObject[];
- bodyTags: HtmlTagObject[];
- outputName: string;
- plugin: HtmlWebpackPlugin;
- }>;
- afterTemplateExecution: AsyncSeriesWaterfallHook<{
- html: string;
- headTags: HtmlTagObject[];
- bodyTags: HtmlTagObject[];
- outputName: string;
- plugin: HtmlWebpackPlugin;
- }>;
- beforeAssetTagGeneration: AsyncSeriesWaterfallHook<{
- assets: {
- publicPath: string;
- js: Array<string>;
- css: Array<string>;
- favicon?: string;
- manifest?: string;
- };
- outputName: string;
- plugin: HtmlWebpackPlugin;
- }>;
- beforeEmit: AsyncSeriesWaterfallHook<{
- html: string;
- outputName: string;
- plugin: HtmlWebpackPlugin;
- }>;
- afterEmit: AsyncSeriesWaterfallHook<{
- outputName: string;
- plugin: HtmlWebpackPlugin;
- }>;
- }
- /**
- * A tag element according to the htmlWebpackPlugin object notation
- */
- interface HtmlTagObject {
- /**
- * Attributes of the html tag
- * E.g. `{'disabled': true, 'value': 'demo'}`
- */
- attributes: {
- [attributeName: string]: string | boolean;
- };
- /**
- * The tag name e.g. `'div'`
- */
- tagName: string;
- /**
- * The inner HTML
- */
- innerHTML?: string;
- /**
- * Whether this html must not contain innerHTML
- * @see https://www.w3.org/TR/html5/syntax.html#void-elements
- */
- voidTag: boolean;
- }
- }
|