如何在 React 的构建阶段禁用 ESLint
How to disable ESLint during build phase in React
我正在使用 create-react-app 并为 eslint 配置了我的项目。下面是我的 .eslintrc 文件。
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"react-hooks"
],
"extends": [
"plugin:prettier/recommended",
"airbnb-typescript-prettier",
"prettier",
"plugin:import/typescript"
],
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
// Make prettier code formatting suggestions more verbose.
"prettier/prettier": [
"warn"
],
"camelcase": "warn",
"no-console": "error",
"no-prototype-builtins": "warn",
"arrow-body-style": "warn",
"prefer-arrow-callback": "warn",
"jsx-a11y/click-events-have-key-events": "warn",
"jsx-a11y/no-noninteractive-element-interactions": "warn",
// Disable <Fragment> => <> replacement. Feel free to change
"react/jsx-fragments": "off",
"react/destructuring-assignment": "warn",
"react/no-unused-prop-types": "warn",
//TODO: Remove this rule later
"react/jsx-props-no-spreading": "off",
"react/require-default-props": 0,
"react-hooks/exhaustive-deps": "warn",
// Disable prefer default export
"import/prefer-default-export": "off",
"no-underscore-dangle": "off",
"@typescript-eslint/camelcase": 0,
"@typescript-eslint/no-empty-function": "warn",
"@typescript-eslint/ban-ts-comment": "warn",
"@typescript-eslint/ban-types": "warn",
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/no-empty-interface": "warn",
"@typescript-eslint/no-inferrable-types": "warn",
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": true
}
]
}
}
问题是,在构建阶段它占用了大量内存。因此,我无法使用内存为 8Gb 的 docker。有什么方法可以仅在构建阶段 期间禁用 eslint ?我在开发过程中需要这些规则,但不希望它们影响我的构建阶段。有人可以帮忙吗?提前致谢。
您可以通过将 DISABLE_ESLINT_PLUGIN=true
添加到 package.json
中“脚本”部分的“构建”来实现:
{
"scripts": {
"start": "react-scripts start",
"build": "DISABLE_ESLINT_PLUGIN=true react-scripts build",
"test": "react-scripts test"
}
}
我正在使用 create-react-app 并为 eslint 配置了我的项目。下面是我的 .eslintrc 文件。
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"react-hooks"
],
"extends": [
"plugin:prettier/recommended",
"airbnb-typescript-prettier",
"prettier",
"plugin:import/typescript"
],
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
// Make prettier code formatting suggestions more verbose.
"prettier/prettier": [
"warn"
],
"camelcase": "warn",
"no-console": "error",
"no-prototype-builtins": "warn",
"arrow-body-style": "warn",
"prefer-arrow-callback": "warn",
"jsx-a11y/click-events-have-key-events": "warn",
"jsx-a11y/no-noninteractive-element-interactions": "warn",
// Disable <Fragment> => <> replacement. Feel free to change
"react/jsx-fragments": "off",
"react/destructuring-assignment": "warn",
"react/no-unused-prop-types": "warn",
//TODO: Remove this rule later
"react/jsx-props-no-spreading": "off",
"react/require-default-props": 0,
"react-hooks/exhaustive-deps": "warn",
// Disable prefer default export
"import/prefer-default-export": "off",
"no-underscore-dangle": "off",
"@typescript-eslint/camelcase": 0,
"@typescript-eslint/no-empty-function": "warn",
"@typescript-eslint/ban-ts-comment": "warn",
"@typescript-eslint/ban-types": "warn",
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/no-empty-interface": "warn",
"@typescript-eslint/no-inferrable-types": "warn",
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": true
}
]
}
}
问题是,在构建阶段它占用了大量内存。因此,我无法使用内存为 8Gb 的 docker。有什么方法可以仅在构建阶段 期间禁用 eslint ?我在开发过程中需要这些规则,但不希望它们影响我的构建阶段。有人可以帮忙吗?提前致谢。
您可以通过将 DISABLE_ESLINT_PLUGIN=true
添加到 package.json
中“脚本”部分的“构建”来实现:
{
"scripts": {
"start": "react-scripts start",
"build": "DISABLE_ESLINT_PLUGIN=true react-scripts build",
"test": "react-scripts test"
}
}