Skip to content

Commit ebd2951

Browse files
committed
fix: if filesystem cache is used, webpack stats or errors are not displayed, #115
1 parent fc86088 commit ebd2951

20 files changed

Lines changed: 196 additions & 12 deletions

File tree

CHANGELOG.md

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

3+
## 4.1.3 (2024-10-28)
4+
5+
- fix: if `filesystem` cache is used, webpack stats or errors are not displayed, #115
6+
- test: allow set the `stats.preset` webpack option to display stats info by testing
7+
38
## 4.1.2 (2024-10-21)
49

510
- fix: issue `file is not resolved` after start->stop->start in serve/watch mode when used cache filesystem, #114

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html-bundler-webpack-plugin",
3-
"version": "4.1.2",
3+
"version": "4.1.3",
44
"description": "HTML Bundler Plugin for Webpack renders HTML templates containing source files of scripts, styles, images. Supports template engines: Eta, EJS, Handlebars, Nunjucks, Pug, TwigJS. Alternative to html-webpack-plugin.",
55
"keywords": [
66
"html",
@@ -54,6 +54,7 @@
5454
"test:coverage": "jest --collectCoverage --config ./test/jest.config.js",
5555
"test:index": "jest --detectOpenHandles --config ./test/jest.config.js --runTestsByPath ./test/index.test.js",
5656
"test:issue": "jest --detectOpenHandles --config ./test/jest.config.js --runTestsByPath ./test/issue.test.js",
57+
"test:messages": "jest --detectOpenHandles --config ./test/jest.config.js --runTestsByPath ./test/messages.test.js",
5758
"test:unit": "jest --detectOpenHandles --collectCoverage --config ./test/jest.config.js --runTestsByPath ./test/unit.test.js",
5859
"test:unitQueryParser": "jest --detectOpenHandles --collectCoverage --config ./test/jest.config.js --runTestsByPath ./test/unit.queryParser.test.js",
5960
"test:verbose": "jest --detectOpenHandles --config ./test/jest.config.js --runTestsByPath ./test/verbose.test.js",

src/Common/Helpers.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ const isFunction = (value) => typeof value === 'function';
2727
*/
2828
const findPlugin = (plugins, name) => plugins.find((item) => item.constructor.name === name);
2929

30+
/**
31+
* Output to console.
32+
*
33+
* @param {*} args
34+
* @return {boolean}
35+
*/
3036
const outToConsole = (...args) => process.stdout.write(args.join(' ') + '\n');
3137

3238
/**

src/Loader/Messages/Exeptions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class LoaderException extends WebpackError {
3636
/**
3737
* @param {ObjectSerializerContext} context context
3838
*/
39-
static serialize(context) {
39+
serialize(context) {
4040
const { write } = context;
4141

4242
write(this.error);
@@ -48,7 +48,7 @@ class LoaderException extends WebpackError {
4848
/**
4949
* @param {ObjectDeserializerContext} context context
5050
*/
51-
static deserialize(context) {
51+
deserialize(context) {
5252
const { read } = context;
5353

5454
this.error = read();

src/Plugin/AssetCompiler.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const Config = require('../Common/Config');
2121
const { baseUri, urlPathPrefix, cssLoaderName } = require('../Loader/Utils');
2222
const { findRootIssuer } = require('../Common/CompilationHelpers');
2323
const { isDir } = require('../Common/FileUtils');
24+
const { outToConsole } = require('../Common/Helpers');
2425
const createPersistentCache = require('./createPersistentCache');
2526

2627
const CssExtractModule = require('./Modules/CssExtractModule');
@@ -319,7 +320,10 @@ class AssetCompiler {
319320
});
320321
});
321322

322-
compiler.cache.hooks.shutdown.tapAsync({ name: pluginName, stage: Cache.STAGE_DISK }, () => {
323+
// note: if used `tapAsync` then no webpack statistics or errors will be displayed
324+
// then use in the `done` hook the output of `stats.compilation.options.stats` in Promise.finally
325+
//compiler.cache.hooks.shutdown.tapAsync({ name: pluginName, stage: Cache.STAGE_DISK }, () => {
326+
compiler.cache.hooks.shutdown.tap({ name: pluginName, stage: Cache.STAGE_DISK }, () => {
323327
if (!isCached) {
324328
const cacheData = collectionCache.getData();
325329

@@ -1538,6 +1542,12 @@ class AssetCompiler {
15381542

15391543
compilation.name = compilationName(compilation.name, hasError);
15401544

1545+
// reserved for using `compiler.cache.hooks.shutdown.tapAsync` if used `filesystem` cache
1546+
// let statsOutput = stats.toString(stats.compilation.options.stats);
1547+
// if (statsOutput) {
1548+
// outToConsole(statsOutput);
1549+
// }
1550+
15411551
if (this.exceptions.size > 0) {
15421552
const messages = Array.from(this.exceptions).join('\n\n');
15431553
this.exceptions.clear();
@@ -1558,7 +1568,6 @@ class AssetCompiler {
15581568
* Called when the compiler is closing or a watching compilation has stopped.
15591569
*/
15601570
shutdown() {
1561-
//console.log('xxxx shutdown: ', {});
15621571
PluginService.shutdown(this.compilation?.compiler);
15631572
}
15641573
}

test/cases/_pug/filter-markdown/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const HtmlBundlerPlugin = require('@test/html-bundler-webpack-plugin');
33

44
module.exports = [
55
{
6-
name: 'config_2',
6+
name: 'config_1',
77
mode: 'production',
88

99
output: {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Test</title>
5+
</head>
6+
<body>
7+
<h1>Hello World!</h1>
8+
<script src="main.6ad9992e.js"></script>
9+
</body>
10+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("Hello World! Test: 123");
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Test</title>
5+
</head>
6+
<body>
7+
<h1>Hello World!</h1>
8+
<script src="main.js"></script>
9+
</body>
10+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('Hello World! Test: 123');

0 commit comments

Comments
 (0)