我正在将项目从Webpack 1迁移到Webpack 2.我在整合eslint时遇到了问题。在我的Webpack 1配置中,我有eslint配置如下:
eslint: {
configFile: path.join(__dirname, "eslint.core.js"),
useEslintrc: false
}
上面的配置工作正常。在Webpack 2中,我在plugins属性下有它
plugins: [
new LoaderOptionsPlugin({
options: {
eslint: {
configFile: path.join(__dirname, "eslint.core.js"),
useEslintrc: false
}
}
}
)
]
在终端中,我收到错误Module build failed: Error: No ESLint configuration found
。我究竟做错了什么?任何帮助表示赞赏。
我正在使用:
"webpack": "2.2.0-rc.3"
"eslint": "3.5.0"
"eslint-loader": "1.5.0"
"eslint-plugin-mocha": "4.5.1"
"eslint-plugin-react": "6.2.2"
答案 0 :(得分:2)
我也有Module build failed: Error: No ESLint configuration found
。
对我来说,解决方案是将所有eslint-loader选项从LoaderOptionsPlugin权限转移到规则。请参阅下面的webpack.config.js。
我的eslint配置文件eslint_conf.js是放在项目根目录中的常用.eslintrc.js的精确副本。
// webpack.config.js
var webpack = require('webpack');
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
context: __dirname + "/src",
entry: './app.js',
output: {
path: path.join(__dirname, 'dist'),
publicPath: '',
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.js$/,
enforce: 'pre',
loader: 'eslint-loader',
exclude: /node_modules/,
options: {
emitWarning: true,
emitError: true,
//failOnWarning: false,
//failOnError: true,
useEslintrc: false,
// configFile: path.join(__dirname, "eslint_conf.js")
configFile: "eslint_conf.js"
}
},
{ test: /\.js$/, exclude: /node_modules/, loader: "babel-loader" },
{ test: /\.(png|jpg)$/, loader: 'file-loader?name=[path][name].[ext]&outputPath=../dist/' },
{
test: /\.(scss|sass|css)$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [{
loader: "css-loader",
options: {
autoprefixer: true,
sourceMap: true,
importLoaders: true
}
},
{
loader: "fast-sass-loader",
options: {
// sourceMap: true
}
}
]
})
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: './index.html'
}),
new ExtractTextPlugin('style.css'),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
'window.jQuery': 'jquery',
'window.$': 'jquery'
})
]
};

要按npm run lintjs
运行eslint,我在package.json中有脚本,如下所示:
"scripts": {
"dev": "nodemon --watch webpack.config.js --exec \"webpack-dev-server --env development\"",
"lintjs": "eslint src --cache --no-eslintrc -c eslint_conf.js",
"build": "webpack --env production"
}
我用:
"devDependencies": {
"autoprefixer": "^6.7.6",
"babel-core": "^6.23.1",
"babel-eslint": "^7.1.1",
"babel-loader": "^6.3.2",
"babel-preset-es2015": "^6.22.0",
"css-loader": "^0.26.2",
"eslint": "^3.17.1",
"eslint-loader": "^1.6.3",
"extract-text-webpack-plugin": "^2.1.0",
"fast-sass-loader": "^1.0.7",
"file-loader": "^0.10.1",
"html-loader": "^0.4.5",
"html-webpack-plugin": "^2.28.0",
"inuitcss": "^6.0.0-beta.4",
"node-sass": "^4.5.0",
"postcss-cssnext": "^2.9.0",
"postcss-import": "^9.1.0",
"postcss-loader": "^1.3.3",
"style-loader": "^0.13.2",
"webpack": "^2.2.1"
}
答案 1 :(得分:0)
在根目录中运行eslint --init
这将为您生成配置文件
只需在webpack conf中使用以下内容
{
loaders: [
{
test: /\.js$/,
loaders: eslint-loader
}
]
}