On this page

Parser options for html modules.

Type:string

Configure how the HTML source is parsed: "document" (the default) parses a full page; any other value is the tag name of the context element to parse the source as that element's inner HTML (a fragment) — e.g. "template" for a neutral fragment, or "tbody" so context-sensitive tags like a bare <tr>/<td> are kept instead of dropped.

Type:boolean | ("..." | { attribute: string; filter?: (attributes: Map<string, string>, value: string) => boolean; tag?: string; type: false | "html" | "script" | "src" | "stylesheet" | "css-url" | "srcset" | "script-module" | "stylesheet-style" | "stylesheet-style-attribute" | "srcdoc" })[]

Configure extraction of URL-like attribute values (e.g. <img src>, <link href>, <script src>) as webpack dependencies. true (default) uses the built-in source list; false disables extraction entirely so attributes are left untouched and <script src> / <link rel="modulepreload"> / <link rel="stylesheet"> no longer become compilation entries; an array lets you customize which tag/attribute pairs are treated as URLs and how they are bundled. Use the string "..." inside the array to inline the defaults. Inline <script> and <style> bodies are always processed. Use webpackIgnore comments or IgnorePlugin to skip individual URLs.

htmlParserOptions.template(source, context): string
Attributes
source:string
Returns:string

Transform the raw source before the html parser extracts dependencies. Receives the source string and a context ({ module, resource }) and must return the html string to parse. Useful for compiling a templating language (Handlebars, EJS, Eta, …) to html so that URLs the template emits are still picked up as webpack dependencies. Runs synchronously.

URL-referenced-asset default hint rules for this parser (JavaScript new URL(...), CSS url(...), HTML <img src> / <link href> / <script src>).