Skip to content

Commit

Permalink
Fail build when Webpack produces warnings or errors (#1842)
Browse files Browse the repository at this point in the history
* Fail build when WebPack produces errors and optionally on warnings

Fixes #1527

* Rework

* Added returns
  • Loading branch information
DreierF committed Dec 7, 2020
1 parent fa18ed5 commit bbcfa95
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions plugins/plugin-webpack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ The options object is optional.
- `extendConfig: (config: WebpackConfig) => WebpackConfig` - extend your webpack config, see below.
- `manifest: boolean | string` - Enable generating a manifest file. The default value is `false`, the default file name is `./asset-manifest.json` if setting manifest to `true`. The relative path is resolved from the output directory.
- `htmlMinifierOptions: boolean | object` - [See below](#minify-html).
- `failOnWarnings: boolean` - Does fail the build when Webpack emits warnings. The default value is `false`.

#### Extending The Default Webpack Config

Expand Down
14 changes: 11 additions & 3 deletions plugins/plugin-webpack/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,18 @@ module.exports = function plugin(config, args = {}) {
reject(err);
return;
}
const info = stats.toJson(extendedConfig.stats);
if (stats.hasErrors()) {
const info = stats.toJson(extendedConfig.stats);
console.error(info.warnings.join('\n-----\n'));
console.error(info.errors.join('\n-----\n'));
console.error('Webpack errors:\n' + info.errors.join('\n-----\n'));
reject(Error(`Webpack failed with ${info.errors} error(s).`));
return;
}
if (stats.hasWarnings()) {
console.error('Webpack warnings:\n' + info.warnings.join('\n-----\n'));
if (args.failOnWarnings) {
reject(Error(`Webpack failed with ${info.warnings} warnings(s).`));
return;
}
}
resolve(stats);
});
Expand Down

1 comment on commit bbcfa95

@vercel
Copy link

@vercel vercel bot commented on bbcfa95 Dec 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.