Skip to content

Commit

Permalink
Fixed: handle compilation.errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshSce committed Jul 19, 2022
1 parent 7b81bb1 commit 4a34543
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ class MinifyHtmlWebpackPlugin {
}

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


if (!this.options.src) {
throw new Error('`src` is missing from the options.')
Expand Down Expand Up @@ -103,13 +108,19 @@ class MinifyHtmlWebpackPlugin {
const afterBuild = this.options.afterBuild || false;
this.root = compilation.options.context;
if (!afterBuild) {
if (Array.isArray(compilation.errors) && compilation.errors.length > 0) {
return;
}
this.process();
}
});

compiler.hooks.done.tap('MinifyHtmlWebpackPluginAfterBuild', compilation => {
compiler.hooks.done.tap('MinifyHtmlWebpackPluginAfterBuild', stats => {
const afterBuild = this.options.afterBuild || false;
if (afterBuild) {
if (stats && stats.compilation && Array.isArray(stats.compilation.errors) && stats.compilation.errors.length > 0) {
return;
}
this.process();
}
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minify-html-webpack-plugin",
"version": "1.1.6",
"version": "1.1.7",
"description": "A webpack plugin to minify html file(s) after building",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down

0 comments on commit 4a34543

Please sign in to comment.