【问题标题】:How to disable ESLint in vue-cli?如何在 vue-cli 中禁用 ESLint?
【发布时间】:2016-12-09 23:17:40
【问题描述】:

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

【问题讨论】:

标签: javascript webpack vue.js vue-cli


【解决方案1】:

这里有一些过时的答案。

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

npm remove @vue/cli-plugin-eslint

【讨论】:

  • 既然原题是3年的,这肯定应该标记为正确答案。
  • 这只有在你想完全去除掉毛时才是正确的。如果您只想去除掉毛“ON SAVE”,请使用 Aakass hand Radbyx 提供的解决方案。
  • 解决方案有效并防止不必要的压力
【解决方案2】:

截至2019, March

vue.config.js

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

【讨论】:

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

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
  • 非常感谢!我回来工作,终于可以专注于编程,而不是删除有用的空格和空行:)
【解决方案4】:

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

使用Eslint:假,

在 config/index.js 中

【讨论】:

  • 修改配置后需要再次npm run dev
  • 这对我不起作用,并且这个选项不再记录在 vue cli 文档中。对我有用的只是从我的项目中删除 @vue/cli-plugin-eslint 模块
【解决方案5】:

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

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

【讨论】:

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

在最新版本中,打开“.eslintrc.js”文件,设置“root: false”.

【讨论】:

  • 当然它不起作用,因为root 只告诉 ESLint 应该解除父文件夹中的所有规则。
  • 可以在 parserOptions 中注释 parser 属性
【解决方案7】:

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

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

【讨论】:

    【解决方案8】:

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

    演示

    /build/
    /config/
    /dist/
    /*.js
    /test/unit/coverage/
    
    /000-xyz/
    
    

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

    【讨论】:

      【解决方案9】:

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

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

      而不是

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

      【讨论】:

        【解决方案10】:

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

        vue.config.js

        然后写下面一行

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

        这个过程对我有用。谢谢

        【讨论】:

          【解决方案11】:

          对于使用 eslint 功能创建的 Vue cli v4 和项目,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 文件。

          【讨论】:

            【解决方案12】:

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

            see this image

            【讨论】:

            • 添加一些描述
            【解决方案13】:

            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 中运行——我没有看到红色曲线。
            • setEslintuseEslint?
            【解决方案14】:

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

            dev: {
               useEslint: false
            },
            

            【讨论】:

              【解决方案15】:

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

              【讨论】:

                【解决方案16】:

                在 vueCli 中 go to package json remove eslint from dependencies 最后你的包 json 必须像这样

                {
                  "name": "vuecompesation",
                  "version": "0.1.0",
                  "private": true,
                  "scripts": {
                    "serve": "vue-cli-service serve",
                    "build": "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%",
                    "last 2 versions",
                    "not dead"
                  ]
                }

                【讨论】:

                  【解决方案17】:

                  这应该可行

                  vue.config.js 中添加这个

                  module.exports = {
                      lintOnSave: false
                  }
                  

                  【讨论】:

                    猜你喜欢
                    • 2018-08-13
                    • 2019-06-25
                    • 2021-04-02
                    • 2020-06-05
                    • 2018-09-15
                    • 2018-12-14
                    • 2018-11-17
                    • 2021-12-14
                    • 2019-03-18
                    相关资源
                    最近更新 更多