Skip to content

Commit 305dc46

Browse files
committed
fix: allow to define the renderStage option lower than PROCESS_ASSETS_STAGE_SUMMARIZE, #137
1 parent bd595a8 commit 305dc46

15 files changed

Lines changed: 183 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 4.12.2 (2025-01-13)
4+
5+
- fix: allow to define the `renderStage` option lower than `PROCESS_ASSETS_STAGE_SUMMARIZE`, #137
6+
37
## 4.12.1 (2025-01-12)
48

59
- fix: incorrect output of preload tag if "crossorigin: true", #139

README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,7 +2413,9 @@ Type: `null | number`
24132413
Default: `Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER - 1`
24142414
24152415
The [stage](https://webpack.js.org/api/compilation-hooks/#list-of-asset-processing-stages) to render output HTML in the [processAssets](https://webpack.js.org/api/compilation-hooks/#processassets) Webpack hook.
2416+
<!--
24162417
The minimal possible stage for the rendering is `PROCESS_ASSETS_STAGE_SUMMARIZE`.
2418+
-->
24172419
24182420
For example:
24192421
@@ -2434,15 +2436,47 @@ module.exports = {
24342436
entry: {
24352437
index: 'src/index.html',
24362438
},
2437-
// Ensures that the CompressionPlugin save the resulting HTML into the `*.html.gz` file
2438-
// after the rendering process in the HtmlBundlerPlugin.
2439+
// ensures that the CompressionPlugin save the resulting HTML into the `*.html.gz` file
2440+
// after the rendering process in the HtmlBundlerPlugin
24392441
renderStage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH + 1,
24402442
}),
24412443
],
24422444
};
24432445

24442446
```
24452447
2448+
Other example with an optimization plugin:
2449+
2450+
```js
2451+
const path = require('path');
2452+
const Compilation = require('webpack/lib/Compilation');
2453+
const HtmlBundlerPlugin = require('html-bundler-webpack-plugin');
2454+
const HtmlMinimizerPlugin = require('html-minimizer-webpack-plugin');
2455+
2456+
module.exports = {
2457+
mode: 'production',
2458+
output: {
2459+
path: path.join(__dirname, 'dist/'),
2460+
},
2461+
plugins: [
2462+
new HtmlBundlerPlugin({
2463+
entry: {
2464+
index: 'src/index.html',
2465+
},
2466+
// ensures that the HTML rendering is called right before the HtmlMinimizerPlugin
2467+
renderStage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE - 1,
2468+
}),
2469+
],
2470+
optimization: {
2471+
minimizer: [
2472+
// this plugin is called at the PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE stage
2473+
new HtmlMinimizerPlugin({}),
2474+
],
2475+
},
2476+
};
2477+
2478+
```
2479+
24462480
> [!TIP]
24472481
> To ensures that the rendering process will be run after all optimizations and after all other plugins
24482482
> set the `renderStage: Infinity + 1`.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html-bundler-webpack-plugin",
3-
"version": "4.12.1",
3+
"version": "4.12.2",
44
"description": "Generates complete single-page or multi-page website from source assets. Build-in support for Markdown, Eta, EJS, Handlebars, Nunjucks, Pug. Alternative to html-webpack-plugin.",
55
"keywords": [
66
"html",

src/Plugin/Option.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -739,9 +739,12 @@ class Option {
739739
let renderStage = this.options.renderStage || Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER - 1;
740740

741741
// minimal possible stage for the rendering
742-
if (renderStage < Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE) {
743-
renderStage = Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE;
744-
}
742+
// TODO: research a really minimal possible stage,
743+
// because, e.g., html-minimizer-webpack-plugin uses the PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE stage,
744+
// and render must be called before this minimizer.
745+
// if (renderStage < Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE) {
746+
// renderStage = Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE;
747+
// }
745748

746749
return renderStage;
747750
}

test/cases/option-preload-html-minimizer-renderStage/expected/css/home.b41afe39.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!doctype html><title>Home</title><meta name=viewport content="width=device-width initial-scale=1"><link rel=preload href=js/main.4a82793c.js as=script><link rel=preload href=css/home.b41afe39.css as=style><link rel=preload href=fonts/open-sans-regular.woff2 as=font type=font/woff2 crossorigin><link rel=preload href=fonts/MaterialIcons-Regular.woff2 as=font type=font/woff2 crossorigin><link href=css/home.b41afe39.css rel=stylesheet><script src=js/main.4a82793c.js></script><h1>Hello World!</h1>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/******/ (() => { // webpackBootstrap
2+
console.log('>> main.js');
3+
4+
/******/ })()
5+
;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
$color: orange;
2+
3+
@font-face {
4+
font-family: 'OpenSans';
5+
src:
6+
url('@fonts/OpenSans/open-sans-regular.woff2') format('woff2');
7+
font-style: normal;
8+
}
9+
10+
11+
@font-face {
12+
font-family: 'MaterialIcons';
13+
src:
14+
url('@fonts/MaterialIcons/MaterialIcons-Regular.woff2') format('woff2');
15+
font-style: normal;
16+
}
17+
18+
h1 {
19+
color: $color;
20+
font-family: 'OpenSans', sans-serif;
21+
}
22+
23+
.mi {
24+
font-family: 'MaterialIcons';
25+
font-size: 64px;
26+
}

0 commit comments

Comments
 (0)