Skip to content

Commit a434ad2

Browse files
committed
feat: add the renderStage option, #134
1 parent c7520bf commit a434ad2

39 files changed

Lines changed: 505 additions & 211 deletions

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change log
22

3+
## 4.11.0 (2024-12-27)
4+
5+
- feat: add the `renderStage` option to define the stage for rendering output HTML in the processAssets Webpack hook
6+
- fix: set default render stage before the stage used in `compression-webpack-plugin` to save completely rendered HTML, #134
7+
- test: add test for the render stage
8+
- docs: add documentation for the new option in readme
9+
310
## 4.10.4 (2024-12-18)
411

512
fix: fail rebuild after changed css file if no html entry defined, #132

README.md

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ See [boilerplate](https://github.com/webdiscus/webpack-html-scss-boilerplate)
509509
- [postprocess](#option-postprocess) (callback)
510510
- [beforeEmit](#option-beforeEmit) (callback)
511511
- [afterEmit](#option-afterEmit) (callback)
512+
- [renderStage](#option-renderStage)
512513
- [preload](#option-preload) (inject preload link tags)
513514
- [integrity](#option-integrity) (inject [subresource integrity hash](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) into script and style tags)
514515
- [minify](#option-minify) and [minifyOptions](#option-minify-options) (minification of generated HTML)
@@ -2402,6 +2403,56 @@ Callback parameters:
24022403
#### [↑ back to contents](#contents)
24032404
24042405
2406+
<a id="option-renderStage" name="option-renderStage"></a>
2407+
2408+
### `renderStage`
2409+
2410+
Type: `null | number`
2411+
2412+
Default: `Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER - 1`
2413+
2414+
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.
2415+
The minimal possible stage for the rendering is `PROCESS_ASSETS_STAGE_SUMMARIZE`.
2416+
2417+
For example:
2418+
2419+
```js
2420+
const path = require('path');
2421+
const Compilation = require('webpack/lib/Compilation');
2422+
const HtmlBundlerPlugin = require('html-bundler-webpack-plugin');
2423+
const CompressionPlugin = require('compression-webpack-plugin');
2424+
2425+
module.exports = {
2426+
mode: 'production',
2427+
output: {
2428+
path: path.join(__dirname, 'dist/'),
2429+
},
2430+
plugins: [
2431+
new CompressionPlugin(),
2432+
new HtmlBundlerPlugin({
2433+
entry: {
2434+
index: 'src/index.html',
2435+
},
2436+
// Ensures that the CompressionPlugin save the resulting HTML into the `*.html.gz` file
2437+
// after the rendering process in the HtmlBundlerPlugin.
2438+
renderStage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH + 1,
2439+
}),
2440+
],
2441+
};
2442+
2443+
```
2444+
2445+
> [!TIP]
2446+
> To ensures that the rendering process will be run after all optimizations and after all other plugins
2447+
> set the `renderStage: Infinity + 1`.
2448+
2449+
> [!CAUTION]
2450+
> Use this option only to order the sequence of asset processing across multiple plugins that use the same [processAssets](https://webpack.js.org/api/compilation-hooks/#processassets) hook.
2451+
2452+
2453+
#### [↑ back to contents](#contents)
2454+
2455+
24052456
<a id="option-preload" name="option-preload"></a>
24062457
24072458
### `preload`
@@ -4844,7 +4895,7 @@ _./partials/people.ejs_
48444895
- [ejs](#loader-option-preprocessor-options-ejs) - generates a fast smallest pure template function w/o runtime (**recommended** for use on client-side)\
48454896
`include` is supported
48464897
- [handlebars](#loader-option-preprocessor-options-handlebars) - generates a precompiled template with runtime (~18KB)\
4847-
`include` is NOT supported (yet)
4898+
`include` is supported
48484899
- [nunjucks](#loader-option-preprocessor-options-nunjucks) - generates a precompiled template with runtime (~41KB)\
48494900
`include` is supported
48504901
- [twig](#loader-option-preprocessor-options-nunjucks) - generates a precompiled template with runtime (~110KB)\
@@ -6825,7 +6876,7 @@ The generated HTML will not contain templating comments.
68256876
68266877
## Also See
68276878
6828-
- [ansis][ansis] - The Node.js lib for ANSI color styling of text in terminal
6879+
- [ansis][ansis] - The Node.js library for ANSI colors and styles in terminal output
68296880
- [pug-loader][pug-loader] The Pug loader for Webpack
68306881
- [pug-plugin][pug-plugin] The Pug plugin for Webpack
68316882

examples/hello-world/webpack.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ module.exports = {
2121
// output filename of extracted CSS
2222
filename: 'css/[name].[contenthash:8].css',
2323
},
24-
watchFiles: {
25-
includes: /\.md/, // watch changes in *.md files, needed for live reload
26-
},
2724
}),
2825
],
2926

0 commit comments

Comments
 (0)