ChatGPT解决这个技术问题 Extra ChatGPT

如何在 vue-cli 中禁用 ESLint?

如何在使用 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,但是在我的项目创建后如何禁用它?

你用的是哪个模板?简单的 webpack?
功能齐全的 Webpack
查看 github.com/vuejs-templates/webpack/blob/… 中的 {{#lint}} 块 - 可能会丢弃整个 preLoaders 块?
@HectorLorenzo 移动它。

W
Wossname

这里有一些过时的答案。

因为 vue-cli 3 使用的是零配置方法,所以禁用它的方法是卸载模块:

npm remove @vue/cli-plugin-eslint

由于原始问题是 3 岁,因此绝对应该将其标记为正确答案。
仅当您想完全去除掉毛时,这才是正确的。如果您只想去除掉毛“ON SAVE”,请使用 Aakass hand Radbyx 提供的解决方案。
解决方案有效并防止不必要的压力
我删除了 @vue/cli-plugin-eslint,现在命令 vue-cli-service serve 显示为 Error: Cannot find module '@vue/cli-plugin-eslint'。还需要什么?
r
radbyx

截至 2019 年 3 月:

vue.config.js 中:

module.exports = {
  ...
  lintOnSave: false
  ...
}

如果您希望 IDE 处理基于 .eslintrc.js 的 linting,但在使用 dev 或 watch npm-scripts 时禁用 linting,这很有效。
npm remove 更好。 cli.vuejs.org/config/#pages 表示只有在安装了 @vue/cli-plugin-eslint 时才会尊重此值。
尽管名称如此,但此设置确实会禁用 lintOnBuild。与卸载 cli 插件的其他答案不同,此答案允许您在需要时仍然使用 vue-cli-service lint 命令。
s
sfuerte

package.json 中更改构建步骤:

...
"scripts": {
    "build": "vue-cli-service build --skip-plugins @vue/cli-plugin-eslint",
    ...
},

这行得通! 2020 年之前的答案希望您将配置添加到不再属于 vue-cli 模板的文件中。
这很好用,请注意,如果您传入其他参数,则需要先执行此操作。示例:vue-cli-service --skip-plugins @vue/cli-plugin-eslint electron:build
非常感谢!我回来工作了,终于可以专注于编程,而不是删除有用的空格和空行:)
d
dKen

从当前版本(^3.0?)开始,您可以设置:

useEslint: false, 

config/index.js


在对配置进行更改后,您需要再次执行 npm run dev
这对我不起作用,并且 vue cli 文档中不再记录此选项。对我有用的只是从我的项目中删除 @vue/cli-plugin-eslint 模块
c
ceejayoz

Vue 的入门项目本身是用模板语言构建的。

查看 the templates{{#lint}} 位),您似乎可以删除整个 preLoaders 块。


此外,如果 OP 想要轻松启用和禁用它,一个廉价的修复方法是向 .eslintignore 文件添加路径。
src/*.js 没有帮助为 src 文件禁用 eslint ...可能需要采取一些额外的步骤? @比尔克里斯韦尔
是的。屏蔽 this part 有效。
@Asqan 您可能想使用 src/**/*.jssrc/**/*.vue 递归地忽略文件
我假设这是在使用“vue create ...”命令之前如何禁用?创建项目后如何禁用 eslint?
F
Felix Jr

https://i.stack.imgur.com/s8PVB.jpg


当然它不起作用,因为 root 只告诉 ESLint 应该解除父文件夹中的所有规则。
您可以在 parserOptions 中评论解析器属性
r
reverie_ss

这里有很多解决方案:https://github.com/vuejs-templates/webpack/issues/73

但是最好的方法是:
在 .eslintignore 中添加一行 **/*,这将忽略所有文件。然后重新运行,如果它是一个网络应用程序!


j
james.garriss

最简单的方法之一就是设置一个 .eslintignore 文件,您要禁用文件夹和文件。

演示

/build/
/config/
/dist/
/*.js
/test/unit/coverage/

/000-xyz/

参考:https://github.com/vuejs-templates/webpack/issues/73#issuecomment-355149342


C
CDT

对于 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-essentialeslint:recommended。未使用的变量或未使用的导入等常见规则在 eslint:recommended 中。 如果您想禁用此类规则,只需删除 eslintConfig 中的 eslint:recommended 并重新启动项目,但不要删除 plugin:vue/vue3-essential,否则 linter 将无法识别 .vue 文件。


E
Eahiya

首先你需要创建一个文件名

vue.config.js

然后写下面一行

module.exports = {
  ...
  lintOnSave: false
  ...
}

这个过程对我有用。谢谢


P
Panayiotis Hiripis

进入文件“tslint.json”并排除 linterOptions 中的所有文件。默认设置仅排除文件夹 node_modules。您也可以在 tsconfig.json 中设置 "strict": false

  "linterOptions": {
    "exclude": [
      "*/**"
    ]
  },

代替

  "linterOptions": {
    "exclude": [
      "node_modules/**"
    ]
  },

Z
ZWHmepsy

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,
    ...
  },
}

不,这会阻止 eslint 在 webstorm 中运行——我没有得到红色曲线。
setEslint 还是 useEslint
对我有用!我不想删除 eslint,只是在我进行开发工作时将其关闭。
A
Alien

config/index.js 中设置 useEslint: false,

see this image


添加一些描述
P
Paul Roub

转到 .eslintrc.js 并添加以下内容:

dev: {
   useEslint: false
},

i
i-wizard

对于 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'
  }
}

k
kiarash shamaii

在 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 个版本”、“未死”] }


G
Gabriel soft

使用以下命令轻松卸载

npm remove @vue/cli-plugin-eslint
yarn remove @vue/cli-plugin-eslint

A
Artur

.eslintignore 中,添加

/*/

Lint 不再抱怨


D
Dim John

我个人为了解决这个问题,创建了一个新项目并从设置中手动发出 Linter / Formatter 选项

我没有解决问题,我只是尽量避免它。希望这可以帮助某人


M
MD SHAYON

这应该工作

在 vue.config.js 添加这个

module.exports = {
    lintOnSave: false
}