Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make Webpack exit with an error when jshint emits warnings?

Using jshint-loader with Webpack, how do I make the webpack command fail when JSHint emits warnings?

The context being that I wish to fail the CI build if linting detects issues.

Currently, I've simply configured Webpack to run jshint-loader on preload of JS files:

// webpack.config.js
module.exports = {
  module: {
    preLoaders: [
      {
        test: /\.js/,
        exclude: /node_modules/,
        loader: 'jshint-loader',
      },
    ],
  },
};
like image 724
aknuds1 Avatar asked Apr 08 '15 09:04

aknuds1


1 Answers

First, jshint-loader must be configured to fail in case issues are found (failOnHint: true), optionally one can also choose to emit warnings as Webpack errors (emitErrors: true).

// webpack.config.js
module.exports = {
  module: {
    preLoaders: [
      {
        test: /\.js/,
        exclude: /node_modules/,
        loader: 'jshint-loader',
      },
    ],
  },
  jshint: {
    emitErrors: true,
    failOnHint: true,
  },
};

Second, Webpack must be told to fail hard, by supplying the --bail option: webpack --bail.

Update:

webpack --bail still doesn't emit a non-zero exit code, argh.

like image 63
aknuds1 Avatar answered Oct 16 '22 08:10

aknuds1