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
代码语言:javascript复制 "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.开发环境自动检测
代码语言:javascript复制npm i eslint-loader babel-eslint -D
.eslintrc
代码语言:javascript复制{
"extends": "standard",
"plugins": ["html"],
"parser": "babel-eslint"
}
webpack.config
代码语言:javascript复制 rules:[
{
test:/.(vue|js|jsx)$/,
loader:'eslint-loader',
exclude:/node_modules/,
enforce:'pre'//预处理
},
...