eslint使用
需引入插件:eslint-loader eslint __eslint-config-airbnb-base eslint-plugin-import
const { resolve } = require('path')
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
entry: './src/js/index.js',
output: {
filename: 'js/built.js',
path: resolve(__dirname, 'build')
},
module: {
rules: [
/**
* 语法检查:eslint-loader eslint
* 注意:只检查源代码,第三方库是不检查的
* 设置检查规则:
* package.json中eslintConfig中设置
*
* "eslintConfig":{
"extends":"airbnb-base"
}
*
* airbnb --> eslint-config-airbnb-base eslint-plugin-import eslint
*/
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
//自动修复eslint的错误
fix: true
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html'
})
],
mode: 'development'
}
package.json配置
"eslintConfig":{
"extends":"airbnb-base"
}