HtmlRspackPlugin

This plugin can be used to create HTML files that are associated with Rspack assets.

new rspack.HtmlRspackPlugin(options);
  • options

    • Type:
    type HtmlRspackPluginOptions = {
      title?: string;
      filename?: string;
      template?: string;
      templateContent?: string;
      templateParameters?: Record<string, string>;
      inject?: 'head' | 'body';
      publicPath?: string;
      scriptLoading?: 'blocking' | 'defer' | 'module';
      chunks?: string[];
      excludedChunks?: string[];
      sri?: 'sha256' | 'sha384' | 'sha512';
      minify?: boolean;
      favicon?: string;
      meta?: Record<string, string | Record<string, string>>;
    };
    • Default: {}
    NameTypeDefaultDescription
    titlestring|undefinedundefinedThe title to use for the generated HTML document.
    filenamestring'index.html'The file to write the HTML to. Defaults to index.html. You can specify a subdirectory here too (eg: pages/index.html).
    templatestring|undefinedundefinedThe template file path.
    templateContentstring|undefinedundefinedThe template file content, priority is greater than template.
    templateParametersRecord<string, string>{}Allows to overwrite the parameters used in the template.
    inject'head'|'body'|undefinedundefinedThe script and link tag inject position in template.
    publicPathstring''The publicPath used for script and link tags.
    scriptLoading'blocking'|'defer'|'module''defer'Modern browsers support non blocking javascript loading ('defer') to improve the page startup performance. Setting to 'module' adds attribute type='module'. This also implies 'defer', since modules are automatically deferred.
    chunksstring[]|undefinedundefinedAllows you to add only some chunks.
    excludedChunksstring[]|undefinedundefinedAllows you to skip some chunks.
    sri'sha256'|'sha384'|'sha512'|undefinedundefinedThe sri hash algorithm, disabled by default.
    minifybooleanfalseControls whether to minify the output.
    faviconstring|undefinedundefinedAdds the given favicon path to the output HTML.
    metaRecord<string, string|Record<string, string>>{}Allows to inject meta-tags.
TIP

If the configuration options provided by rspack.HtmlRspackPlugin cannot meet your needs, you can also directly use the community's html-webpack-plugin plugin.