ESLint 在项目中是以插件的形式存在。所以我们只需要在项目中安装 ESLint 就可以使用
安装 ESLint
1 npm install eslint --save-dev
2 安装 vue 专门的 ESLint 规则插件 @vue/cli-plugin-eslint
3 npm i @vue/cli-plugin-eslint --save-dev
添加配置文件
配置文件常用的方法有两种:
1 在 package.json中添加
{
"name": "mypackage",
"version": "0.0.1",
"eslintConfig": {
"plugins": ["example"],
"env": {
"example/custom": true
}
}
}
2 在项目根目录添加独立的配置文件.eslintrc.js
module.exports = {
root: true,
env: {
node: true
},
parserOptions: {
parser: "babel-eslint"
},
rules: {
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
"indent": ["error", 2]
}
};
参照:浅谈 vue-cli 4.0 中的 ESLint_杰~JIE的博客-CSDN博客