HTML

Rspack supports generating HTML files using the following plugins, and automatically injecting the generated CSS and JavaScript files into the HTML. This is particularly useful for Rspack bundles that contain filename hashes, as the hashes can change with each Rspack build.

HtmlWebpackPlugin

Rspack fully supports HtmlWebpackPlugin.

rspack.config.js
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');

module.exports = {
  entry: 'index.js',
  output: {
    path: path.resolve(__dirname, './dist'),
    filename: 'index_bundle.js',
  },
  plugins: [new HtmlWebpackPlugin()],
};

For all configuration options, see the plugin documentation.

Built-in HtmlRspackPlugin

HtmlRspackPlugin is a high-performance HTML plugin implemented in Rust, offering significantly better build performance than the HtmlWebpackPlugin, especially when building a large number of HTML files.

rspack.config.js
const rspack = require('@rspack/core');

module.exports = {
  entry: 'index.js',
  output: {
    path: path.resolve(__dirname, './dist'),
    filename: 'index_bundle.js',
  },
  plugins: [new rspack.HtmlRspackPlugin()],
};

For all configuration options, see the plugin documentation.