我正在尝试按照此说明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'。这些属性是有效的: object {amd?,bail?,cache?,context?,dependencies?,devServer?,devtool ?, entry,externals?,loader?,module ?, name?,node?,output?,performance?,plugins ?, prof ile?,recordsInputPath?,recordsOutputPath?,recordsPath?,resolve?,resolveLoader?,stats?,target?,watch?,watchOptions? } 错别字:请纠正。 对于加载程序选项:webpack 2不再允许配置中的自定义属性。
答案 0 :(得分:45)
他们网站上的说明似乎已经过时,因为这确实不起作用。在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
}
}]
}]
},
};
答案 1 :(得分:-1)
对我唯一有用的是手动更改jshint-loader的文件。
更改后,该函数将如下所示:
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... }