npm i eslint eslint-config-standard eslint-plugin-standard eslint-plugin-promise eslint-plugin-import eslint-plugin-node eslint-plugin-html
2.新键配置文件.eslintrc
{
"extends": "standard",
"plugins": ["html"]
}
3.配置package.json
"scripts": {
...
"lint":"eslint --ext .js --ext .jsx --ext .vue client/",//检测代码
"lint-fix":"eslint --fix --ext .js --ext .jsx --ext .vue client/"//自动修复
},
...
运行命令 npm run lint
4.开发环境自动检测
npm i eslint-loader babel-eslint -D
.eslintrc
{
"extends": "standard",
"plugins": ["html"],
"parser": "babel-eslint"
}
webpack.config
rules:[
{
test:/\.(vue|js|jsx)$/,
loader:'eslint-loader',
exclude:/node_modules/,
enforce:'pre'//预处理
},
...