【问题标题】:webpack3 jshint-loader does not workwebpack3 jshint-loader 不工作
【发布时间】:2017-12-29 15:35:47
【问题描述】:

我正在尝试遵循此说明https://webpack.js.org/loaders/jshint-loader/ 并得到一个错误:

我的配置文件:

const path = require('path');

    module.exports = {
      entry: {
        app: './index.js'
      },
      output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist')
      },

      module: {
        rules: [
          {
            test: /\.js$/, // include .js files
            enforce: "pre", // preload the jshint loader
            exclude: /node_modules/, // exclude any and all files in the node_modules folder
            use: [
              {
                loader: "jshint-loader"
              }
            ]
          }
        ]
      },

      // more options in the optional jshint object
      jshint: {
        // any jshint option http://www.jshint.com/docs/options/
        // i. e.
        camelcase: true,

        // jshint errors are displayed by default as warnings
        // set emitErrors to true to display them as errors
        emitErrors: false,

         // jshint to not interrupt the compilation
         // if you want any file with jshint errors to fail
         // set failOnHint to true
         failOnHint: false,

         // custom reporter function
         reporter: function(errors) { }
       }
    };

错误文本:

配置对象无效。 Webpack 已使用与 API 模式不匹配的配置对象进行初始化。 - 配置具有未知属性“jshint”。这些属性是有效的: 对象 { amd?,保释?,缓存?,上下文?,依赖项?,devServer?,devtool?,条目,外部?,加载程序?,模块?,名称?,节点?,输出?,性能?,插件?,教授 ile?、recordsInputPath?、recordsOutputPath?、recordsPath?、resolve?、resolveLoader?、stats?、target?、watch?、watchOptions? } 错别字:请更正。 对于加载器选项:webpack 2 不再允许在配置中自定义属性。

【问题讨论】:

    标签: webpack jshint webpack-3


    【解决方案1】:

    他们网站上的说明似乎已经过时,因为这确实不起作用。 Github 上有一个未解决的问题。

    这个配置应该可以工作:

    const path = require('path');
    
    module.exports = {
      entry: {
        app: './index.js'
      },
      output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist')
      },
    
      module: {
        rules: [{
          test: /\.js$/, // include .js files
          enforce: "pre", // preload the jshint loader
          exclude: /node_modules/, // exclude any and all files in the node_modules folder
          use: [{
            loader: "jshint-loader",
            // more options in the optional jshint object
            options: {  // ⬅ formally jshint property
              camelcase: true,
              emitErrors: false,
              failOnHint: false
            }
          }]
        }]
      },
    };
    

    【讨论】:

    • 是的,这个正在工作。在搜索了一些错误语法参考之后
    • 谁能解释一下答案中已修复的内容,以便它开始工作?
    • jshint 属性现在是use 作为optionsjshint-loader 下的子属性。
    【解决方案2】:

    唯一对我有用的是手动更改 jshint-loader 的文件。

    1. 转到[您的项目路径]/node_modules/jshint-loader/index.js。
    2. 查找函数“jsHint”(第 61 行),然后转到第 63 行。
    3. 将“if(this.options.jshint)”更改为“if(options.jshint)”。
    4. 更改后,函数将如下所示:

      功能 jsHint(输入,选项){ // 复制选项到自己的对象 如果(选项.jshint){ for(this.options.jshint 中的变量名称){ 选项[名称] = this.options.jshint[名称]; } } //函数继续... }

    【讨论】:

      猜你喜欢
      • 2014-12-08
      • 2016-03-31
      • 2017-07-15
      • 2016-02-28
      • 2016-06-06
      • 2018-02-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多