如何在使用 vue-cli
生成的项目中禁用 ESlint
?
preLoaders: [
{
test: /\.vue$/,
loader: 'eslint',
include: projectRoot,
exclude: /node_modules/
},
{
test: /\.js$/,
loader: 'eslint',
include: projectRoot,
exclude: /node_modules/
}
]
如果我删除 loader: 'eslint'
行,它将无法编译,与将其设置为空字符串相同。我知道我可以在初始化阶段选择退出 ESLint
,但是在我的项目创建后如何禁用它?
这里有一些过时的答案。
因为 vue-cli 3 使用的是零配置方法,所以禁用它的方法是卸载模块:
npm remove @vue/cli-plugin-eslint
截至 2019 年 3 月:
在 vue.config.js
中:
module.exports = {
...
lintOnSave: false
...
}
vue-cli-service lint
命令。
在 package.json
中更改构建步骤:
...
"scripts": {
"build": "vue-cli-service build --skip-plugins @vue/cli-plugin-eslint",
...
},
从当前版本(^3.0?)开始,您可以设置:
useEslint: false,
在config/index.js
npm run dev
@vue/cli-plugin-eslint
模块
Vue 的入门项目本身是用模板语言构建的。
查看 the templates({{#lint}}
位),您似乎可以删除整个 preLoaders
块。
src/*.js
没有帮助为 src 文件禁用 eslint ...可能需要采取一些额外的步骤? @比尔克里斯韦尔
src/**/*.js
和 src/**/*.vue
递归地忽略文件
https://i.stack.imgur.com/s8PVB.jpg
root
只告诉 ESLint 应该解除父文件夹中的所有规则。
这里有很多解决方案:https://github.com/vuejs-templates/webpack/issues/73
但是最好的方法是:
在 .eslintignore 中添加一行 **/*
,这将忽略所有文件。然后重新运行,如果它是一个网络应用程序!
最简单的方法之一就是设置一个 .eslintignore
文件,您要禁用文件夹和文件。
演示
/build/
/config/
/dist/
/*.js
/test/unit/coverage/
/000-xyz/
参考:https://github.com/vuejs-templates/webpack/issues/73#issuecomment-355149342
对于 Vue cli v4 和选择了 eslint 功能创建的项目,package.json 中有一个 eslintConfig
属性:
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
extends
指定一些规则预设,默认为 plugin:vue/vue3-essential
和 eslint:recommended
。未使用的变量或未使用的导入等常见规则在 eslint:recommended
中。 如果您想禁用此类规则,只需删除 eslintConfig
中的 eslint:recommended
并重新启动项目,但不要删除 plugin:vue/vue3-essential
,否则 linter 将无法识别 .vue
文件。
首先你需要创建一个文件名
vue.config.js
然后写下面一行
module.exports = {
...
lintOnSave: false
...
}
这个过程对我有用。谢谢
进入文件“tslint.json”并排除 linterOptions 中的所有文件。默认设置仅排除文件夹 node_modules。您也可以在 tsconfig.json 中设置 "strict": false
"linterOptions": {
"exclude": [
"*/**"
]
},
代替
"linterOptions": {
"exclude": [
"node_modules/**"
]
},
setEslint: false
为我工作!
module.exports = {
dev: {
...
// Use Eslint Loader?
// If true, your code will be linted during bundling and
// linting errors and warnings will be shown in the console.
useEslint: false,
...
},
}
setEslint
还是 useEslint
?
转到 .eslintrc.js
并添加以下内容:
dev: {
useEslint: false
},
对于 vue3 用户,只需将 eslintrc.js 文件中的 parserOptions 注释掉即可。它对我有用,因为有时掉毛会令人沮丧
module.exports = {
root: true,
env: {
node: true
},
'extends': [
'plugin:vue/vue3-essential',
'eslint:recommended'
],
// parserOptions: {
// parser: 'babel-eslint'
// },
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
}
}
在 vueCli 中转到 package json 最后从依赖项中删除 eslint 你的包 json 必须像这样
{“名称”:“vuecompesation”,“版本”:“0.1.0”,“私有”:true,“脚本”:{“服务”:“vue-cli-service”,“构建”:“vue- cli-service build" }, "dependencies": { "core-js": "^3.6.5", "vue": "^3.0.0" }, "devDependencies": { "@vue/cli-plugin- babel": "~4.5.0", "@vue/cli-plugin-eslint": "~4.5.0", "@vue/cli-service": "~4.5.0", "@vue/compiler- sfc": "^3.0.0", "babel-eslint": "^10.1.0" }, "eslintConfig": { "root": true, "env": { "node": true }, "extends" : [ "plugin:vue/vue3-essential", "eslint:recommended" ], "parserOptions": { "parser": "babel-eslint" }, "rules": {} }, "browserslist": [ "> 1%”、“最近 2 个版本”、“未死”] }
使用以下命令轻松卸载
npm remove @vue/cli-plugin-eslint
yarn remove @vue/cli-plugin-eslint
在 .eslintignore
中,添加
/*/
Lint 不再抱怨
我个人为了解决这个问题,创建了一个新项目并从设置中手动发出 Linter / Formatter 选项
我没有解决问题,我只是尽量避免它。希望这可以帮助某人
这应该工作
在 vue.config.js 添加这个
module.exports = {
lintOnSave: false
}
不定期副业成功案例分享
@vue/cli-plugin-eslint
,现在命令vue-cli-service serve
显示为Error: Cannot find module '@vue/cli-plugin-eslint'
。还需要什么?