问题是,在我进行开发时,每次ESLint出现问题时,构建都会中断,不会编译代码。
我将emitWarning设置为:对,但不起作用。我的反应项目是与webpack,中微子JS,esLint,airbnb一起开发的。
运行生成时出现错误
错误在./src/index.jsx模块构建失败(从./node_dist/ eslint /dist/cjs.js):模块失败是因为一个eslint错误。
文件中的代码结构
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"],
},
},
],
},
},
},
}),发布于 2021-05-10 14:58:41
您需要将failOnWarning添加为false
emitWarning: true,
failOnWarning: false,发布于 2021-10-06 19:15:16
我不得不结合几个解决方案来解决这个问题。这不是最优雅的,但很有效。
将RUN_ESLINT=true添加到package.json监视脚本中:
export RUN_ESLINT=true && webpack --config webpack.config.js --watch --mode development将module.exports重写为一个函数:
module.exports = () => {
...
return {}
}使用webpack.EnvironmentPlugin导入env变量。
new webpack.EnvironmentPlugin(["NODE_ENV", "DEBUG", "RUN_ESLINT"]);有条件地添加ESLintPlugin:
const plugins = [...];
if (process.env.RUN_ESLINT) {
plugins.push(new ESLintPlugin());
}这样我就可以继续使用我的npm run build和npm run watch脚本,就像我在添加eslint之前一样。
https://stackoverflow.com/questions/67413167
复制相似问题