问题描述
在我的一个Vue项目中的某个时候,Eslint由于任何错误(例如“字符串必须使用单引号”或“声明了变量但从未使用过”)而开始破坏构建。此外,格式错误不会自动纠正(尽管应该纠正吗?)。我不知道这是什么时候发生的,是什么原因造成的。可能在npm install
之后。
我发现通过将emitWarning: true
添加到eslint config来解决该问题的多种建议,但不幸的是,这对我来说是行不通的。
在我看来,有时首次构建尝试会成功,并且只有在我更改了代码中的某些内容,保存并重新启动服务器后,“检测到”并抛出了错误。同样,eslint似乎只关心当前在VS Code中实际打开的文件,如果我关闭文件并重新启动,则eslint不再关心那里的格式不正确。
module.exports = {
root: true,env: {
node: true,"es6": true
},extends: [
"plugin:vue/essential","@vue/standard"
],rules: {
"no-console": process.env.NODE_ENV === "production" ? "error" : "off","no-debugger": process.env.NODE_ENV === "production" ? "error" : "off","indent": ["error",4],"semi": ["error","always"],"space-before-function-paren": ["error","never"],"quotes": ["error","single"]
},parserOptions: {
parser: "babel-eslint",sourceType: "module",ecmaVersion: 6,emitWarning: true,// tried with and without this
emitError: false,// tried with and without this
failOnError: false,// tried with and without this
failOnWarning: false // tried with and without this
}
};
我的其他Vue项目运行正常。我无法查明设置上的任何有意义的区别。
如何阻止eslint破坏版本?还有什么可能是错的?我将不胜感激!
解决方法
您可以通过更改build
文件中的package.json
脚本,使构建命令跳过ESlint:
"scripts": {
"build": "vue-cli-service build --skip-plugins @vue/cli-plugin-eslint",}
如果不是项目中使用的插件,请用相应的插件替换。