Skip to content

Commit

Permalink
Add onlyOnError option
Browse files Browse the repository at this point in the history
Trigger a notification only on error.
  • Loading branch information
Sergej Müller authored and Gvozd committed Nov 15, 2020
1 parent a120544 commit 39a2bea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 9 additions & 1 deletion README.md
Expand Up @@ -78,12 +78,20 @@ new WebpackNotifierPlugin({excludeWarnings: true});

### Always Notify

Trigger a notification every time. Call it "noisy-mode".
Trigger a notification every time. Call it "noisy-mode".

```js
new WebpackNotifierPlugin({alwaysNotify: true});
```

### Notify on error

Trigger a notification only on error.

```js
new WebpackNotifierPlugin({onlyOnError: true});
```

### Skip Notification on the First Build

Do not notify on the first build. This allows you to receive notifications on subsequent incremental builds without being notified on the initial build.
Expand Down
6 changes: 3 additions & 3 deletions index.js
Expand Up @@ -40,10 +40,10 @@ WebpackNotifierPlugin.prototype.compileMessage = function(stats) {
if (stats.hasErrors()) {
error = findFirstDFS(stats.compilation, 'errors');

} else if (stats.hasWarnings() && !this.options.excludeWarnings) {
} else if (stats.hasWarnings() && !this.options.excludeWarnings && !this.options.onlyOnError) {
error = findFirstDFS(stats.compilation, 'warnings');

} else if (!this.lastBuildSucceeded || this.options.alwaysNotify) {
} else if ((!this.lastBuildSucceeded || this.options.alwaysNotify) && !this.options.onlyOnError) {
this.lastBuildSucceeded = true;
return (hasEmoji ? '✅ ' : '') + 'Build successful';

Expand All @@ -53,7 +53,7 @@ WebpackNotifierPlugin.prototype.compileMessage = function(stats) {

this.lastBuildSucceeded = false;

var message;
var message = '';
if (error.module && error.module.rawRequest)
message = error.module.rawRequest + '\n';

Expand Down

0 comments on commit 39a2bea

Please sign in to comment.