jshint loader module for webpack
Apply the jshint loader as pre/postLoader in your webpack configuration:
moduleexports =module:preLoaders:test: /\.js$/ // include .js filesexclude: /node_modules/ // exclude any and all files in the node_modules folderloader: "jshint-loader"// more options in the optional jshint objectjshint:// any jshint option// i. e.camelcase: true// jshint errors are displayed by default as warnings// set emitErrors to true to display them as errorsemitErrors: false// jshint to not interrupt the compilation// if you want any file with jshint errors to fail// set failOnHint to truefailOnHint: false// custom reporter function
jshint-loader will provide a default reporter.
However, if you prefer a custom reporter, pass a function under the
reporter key in
jshint options. (see usage above)
The reporter function will be passed an array of errors/warnings produced by jshint with the following structure:
id: string usually '(error)'code: string error/warning codereason: string error/warning messageevidence: string a piece of code that generated this errorline: numbercharacter: numberscope: string message scope;usually '(main)' unless the code was eval'ed][+ a few other legacy fields that you don't need to worry about// ...// more errors/warnings
The reporter function will be excuted with the loader context as
this. You may emit messages using
this.emitError(...). See webpack docs on loader context.
Note: jshint reporters are not compatible with jshint-loader! This is due to the fact that reporter input is only processed from one file; not multiple files. Error reporting in this manner differs from tranditional reporters for jshint since the loader plugin (i.e. jshint-loader) is executed for each source file; and thus the reporter is executed for each file.
The output in webpack CLI will usually be:
WARNING in /path/to/filejs<reporter output>