webpack3 jshint-loader does not work

☆樱花仙子☆ 提交于 2019-12-03 05:45:19
Tom Van Rompaey

The instructions on their website seem to be outdated as this isn't working indeed. There's an open issue about this on Github.

This configuration should work:

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
        }
      }]
    }]
  },
};

The only thing that worked for me was changing the jshint-loader's file manually.

  1. Go to [your project path]/node_modules/jshint-loader/index.js.
  2. Look for the function "jsHint" (line 61) and then go to line 63.
  3. Change "if(this.options.jshint)" for "if(options.jshint)".
  4. After the change, the function will be looking like this:

    
    function jsHint(input, options) {
        // copy options to own object
        if(options.jshint) {
            for(var name in this.options.jshint) {
                options[name] = this.options.jshint[name];
            }
        }
        //function goes on...
    }
    
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!