1.根目录下创建.eslintrc.json文件
实现方法:在根目录下创建.eslintrc.json文件,然后设置自己的eslint配置
{
"extends": ["react-app"],
"rules": {
"eqeqeq": "off"
}
}
2.在 package.json 中修改为一下
"eslintConfig": {
"extends": "react-app",
"rules": {
"no-undef": "off",
"no-restricted-globals": "off",
"no-unused-vars": "off"
}
}
3.
{
test: /\.(js|mjs|jsx|ts|tsx)$/,
enforce: 'pre',
use: [
{
options: {
cache: true,
formatter: require.resolve('react-dev-utils/eslintFormatter'),
eslintPath: require.resolve('eslint'),
resolvePluginsRelativeTo: __dirname,
// @remove-on-eject-begin
ignore: isExtendingEslintConfig,
baseConfig: isExtendingEslintConfig
? undefined
: {
extends: [require.resolve('eslint-config-react-app')],
},
useEslintrc: isExtendingEslintConfig,
// @remove-on-eject-end
},
loader: require.resolve('eslint-loader'),
},
],
include: paths.appSrc,
}
4.修改webpack.config.js
1. npm run eject 来暴露配置文件,(不可逆的)
2.直接注释 或修改 extensions: [‘js’, ‘mjs’, ‘jsx’, , ‘tsx’],需要验证什么加什么
// !disableESLintPlugin &&
// new ESLintPlugin({
// // Plugin options
// // extensions: ['js', 'mjs', 'jsx', , 'tsx'],
// extensions: ['vue'],
// formatter: require.resolve('react-dev-utils/eslintFormatter'),
// eslintPath: require.resolve('eslint'),
// failOnError: !(isEnvDevelopment && emitErrorsAsWarnings),
// context: paths.appSrc,
// cache: true,
// cacheLocation: path.resolve(
// paths.appNodeModules,
// '.cache/.eslintcache'
// ),
// // ESLint class options
// cwd: paths.appPath,
// resolvePluginsRelativeTo: __dirname,
// baseConfig: {
// extends: [require.resolve('eslint-config-react-app/base')],
// rules: {
// ...(!hasJsxRuntime && {
// 'react/react-in-jsx-scope': 'error',
// }),
// },
// },
// }),