代码之家  ›  专栏  ›  技术社区  ›  Janning Vygen

vue和eslint只是linting更改的文件

  •  0
  • Janning Vygen  · 技术社区  · 6 年前

    我们使用vue-cli和eslint插件,我们有一个.eslintrc配置,如下所示:

    const devOff = process.env.NODE_ENV === 'production' ? 'error' : 'warn';
    
    module.exports = {
      root: true,
      env: {
        node: true
      },
      'extends': [
        'plugin:vue/essential',
        "eslint:recommended"
      ],
      rules: {
        'no-console': devOff,
      },
      parserOptions: {
        parser: 'babel-eslint'
      }
    };
    

    当我们奔跑时 npm run build 我们第一次遇到错误,这很好,因为eslint应该在为生产构建时报告错误。

    警告:意外的控制台语句(无控制台)。。。

    当我们奔跑时 npm运行构建 同样,在不改变任何东西的情况下,构建运行良好。在我看来,eslint正在缓存已经解析的文件,而不管是否有错误。

    我在中找到了CLI optin-cache eslint guide 但我无法在vue.config.js或.eslintrc.js中设置此选项

    如果我们在任何文件中都有任何linting错误,我如何设置vue/eslint以重复失败生产构建。

    0 回复  |  直到 6 年前
        1
  •  0
  •   IVO GELOV    6 年前

    这就是我在所有项目中解决这个问题的方法:

    // vue.config.js
    module.exports =
    {
      chainWebpack: config =>
      {
        config.module.rule('eslint').use('eslint-loader').loader('eslint-loader').tap(options =>
        {
          delete options.cacheIdentifier;
          options.cache = false; // otherwise on each restart cached errors won't be shown !!!
          return options;
        });
        config.module.rule('vue').use('vue-loader').loader('vue-loader').tap(options =>
        {
          delete options.cacheDirectory;
          return options;
        });
        config.module.rule('vue').uses.delete('cache-loader');
        config.module.rule('js').uses.delete('cache-loader');
      }
    }