Skip to content

Commit 4a34543

Browse files
committed
Fixed: handle compilation.errors
1 parent 7b81bb1 commit 4a34543

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

index.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ class MinifyHtmlWebpackPlugin {
7474
}
7575

7676
const dir = this.options.dir || this.root;
77+
if (!dir) {
78+
console.error("Either missing base `dir` to find the files or the root of webpack context not provided.")
79+
return;
80+
}
81+
7782

7883
if (!this.options.src) {
7984
throw new Error('`src` is missing from the options.')
@@ -103,13 +108,19 @@ class MinifyHtmlWebpackPlugin {
103108
const afterBuild = this.options.afterBuild || false;
104109
this.root = compilation.options.context;
105110
if (!afterBuild) {
111+
if (Array.isArray(compilation.errors) && compilation.errors.length > 0) {
112+
return;
113+
}
106114
this.process();
107115
}
108116
});
109117

110-
compiler.hooks.done.tap('MinifyHtmlWebpackPluginAfterBuild', compilation => {
118+
compiler.hooks.done.tap('MinifyHtmlWebpackPluginAfterBuild', stats => {
111119
const afterBuild = this.options.afterBuild || false;
112120
if (afterBuild) {
121+
if (stats && stats.compilation && Array.isArray(stats.compilation.errors) && stats.compilation.errors.length > 0) {
122+
return;
123+
}
113124
this.process();
114125
}
115126
})

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "minify-html-webpack-plugin",
3-
"version": "1.1.6",
3+
"version": "1.1.7",
44
"description": "A webpack plugin to minify html file(s) after building",
55
"scripts": {
66
"test": "echo \"Error: no test specified\" && exit 1"

0 commit comments

Comments
 (0)