首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >忽略或防止ESLint错误破坏React webpack项目中的构建

忽略或防止ESLint错误破坏React webpack项目中的构建
EN

Stack Overflow用户
提问于 2021-05-06 06:51:41
回答 2查看 1.7K关注 0票数 4

问题是,在我进行开发时,每次ESLint出现问题时,构建都会中断,不会编译代码。

我将emitWarning设置为:对,但不起作用。我的反应项目是与webpack,中微子JS,esLint,airbnb一起开发的。

运行生成时出现错误

错误在./src/index.jsx模块构建失败(从./node_dist/ eslint /dist/cjs.js):模块失败是因为一个eslint错误。

文件中的代码结构

代码语言:javascript
复制
const path = require("path");
const airbnb = require("@neutrinojs/airbnb");
const react = require("@neutrinojs/react");

module.exports = {
  options: {
    root: __dirname,
  },
  use: [
    (neutrino) => {
      neutrino.config.resolve.modules
        .add("node_modules")
        .add(path.resolve(__dirname, "src"));

      neutrino.config.resolve.extensions.add(".jsx");

      neutrino.config.resolve.alias.set("react-dom", "@hot-loader/react-dom");
    },
    airbnb({
      eslint: {
        emitWarning: true,
        baseConfig: {
          settings: {
            "import/resolver": "webpack",
          },
          rules: {
            radix: "off",
            "comma-dangle": "off",
            "react/no-danger": "off",
            "react/button-has-type": "off",
            "react/no-find-dom-node": "off",
            "react/jsx-filename-extension": "off",
            "no-console": [
              "error",
              {
                allow: ["warn", "error"],
              },
            ],
            "no-alert": "off",
            "no-plusplus": "off",
            "no-else-return": "off",
            "no-nested-ternary": "off",
            "no-underscore-dangle": "off",
            "no-restricted-syntax": "off",
            "max-len": 0,
            "quote-props": "off",
            "default-case": "off",
            "class-methods-use-this": "off",
            "import/prefer-default-export": "off",
            "react/no-array-index-key": "off",
            "jsx-a11y/click-events-have-key-events": "off",
            "jsx-a11y/label-has-for": [
              "error",
              {
                required: {
                  some: ["nesting", "id"],
                },
              },
            ],
          },
        },
      },
    }),
EN

回答 2

Stack Overflow用户

发布于 2021-05-10 14:58:41

您需要将failOnWarning添加为false

代码语言:javascript
复制
emitWarning: true,
failOnWarning: false,
票数 0
EN

Stack Overflow用户

发布于 2021-10-06 19:15:16

我不得不结合几个解决方案来解决这个问题。这不是最优雅的,但很有效。

将RUN_ESLINT=true添加到package.json监视脚本中:

代码语言:javascript
复制
export RUN_ESLINT=true && webpack --config webpack.config.js --watch --mode development

将module.exports重写为一个函数:

代码语言:javascript
复制
module.exports = () => {
...
return {}
}

使用webpack.EnvironmentPlugin导入env变量。

代码语言:javascript
复制
new webpack.EnvironmentPlugin(["NODE_ENV", "DEBUG", "RUN_ESLINT"]);

有条件地添加ESLintPlugin:

代码语言:javascript
复制
const plugins = [...];

if (process.env.RUN_ESLINT) {
  plugins.push(new ESLintPlugin());
}

这样我就可以继续使用我的npm run buildnpm run watch脚本,就像我在添加eslint之前一样。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67413167

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档