简体   繁体   English

当jshint发出警告时,如何使Webpack退出并出现错误?

[英]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? jshint-loaderWebpack结合使用 ,当webpack发出警告时,如何使webpack命令失败?

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配置为在JS文件的预加载上运行jshint-loader:

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

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 ). 首先,必须将jshint-loader配置为在发现问题的情况下失败( failOnHint: true ),还可以选择将警告作为Webpack错误发出( 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 . 其次,必须通过提供--bail选项: webpack --bail来告知--bail webpack --bail

Update: 更新:

webpack --bail still doesn't emit a non-zero exit code, argh. webpack --bail仍然不会发出非零的退出代码,argh。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM