Skip to main content

Render stage

Option: renderStage

Type: null | number

Default: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER - 1

The stage to render output HTML in the processAssets Webpack hook.

For example:

const path = require('path');
const Compilation = require('webpack/lib/Compilation');
const HtmlBundlerPlugin = require('html-bundler-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');

module.exports = {
mode: 'production',
output: {
path: path.join(__dirname, 'dist/'),
},
plugins: [
new CompressionPlugin(),
new HtmlBundlerPlugin({
entry: {
index: 'src/index.html',
},
// ensures that the CompressionPlugin save the resulting HTML into the `*.html.gz` file
// after the rendering process in the HtmlBundlerPlugin
renderStage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH + 1,
}),
],
};

Other example with an optimization plugin:

const path = require('path');
const Compilation = require('webpack/lib/Compilation');
const HtmlBundlerPlugin = require('html-bundler-webpack-plugin');
const HtmlMinimizerPlugin = require('html-minimizer-webpack-plugin');

module.exports = {
mode: 'production',
output: {
path: path.join(__dirname, 'dist/'),
},
plugins: [
new HtmlBundlerPlugin({
entry: {
index: 'src/index.html',
},
// ensures that the HTML rendering is called right before the HtmlMinimizerPlugin
renderStage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE - 1,
}),
],
optimization: {
minimizer: [
// this plugin is called at the PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE stage
new HtmlMinimizerPlugin({}),
],
},
};

tip

To ensures that the rendering process will be run after all optimizations and after all other plugins set the renderStage: Infinity + 1.

caution

Use this option only to order the sequence of asset processing across multiple plugins that use the same processAssets hook.