react:create-react-app关闭eslint

准备工作:

需要先把react项目的配置文件解构出来
配置文件有:config和scripts

操作指令:npm run eject  或  yarn eject

注意:最好在启动项目前就进行解构,这样遇到的bug会少一些

如果在解构后遇到了问题

问题一:报git错误时的操作:git add . ->  git commit -m 'init' ->  yarn eject

问题二:报缺少babel包---报哪个包的缺失就安装哪个包:yarn add 包名 --save 

关闭eslint:

1.方法一

找到config目录下的webpack.config.js文件注释关于eslint的导入和rules规则

	!disableESLintPlugin &&
		new ESLintPlugin({
    
    
			// Plugin options
			extensions: ['js', 'mjs', 'jsx', 'ts', 'tsx'],
			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',
					}),
				},
			},
		}),

1.方法二

在package.json中的eslintConfig内添加关于rules的代码

	"eslintConfig": {
    
    
		"extends": [
			"react-app",
			"react-app/jest"
		],
		"rules": {
    
    
			"no-undef": "off",
			"no-restricted-globals": "off",
			"no-unused-vars": "off"
		}
	}

注意:

更改配置后一定要重启: npm start 或 yarn start

猜你喜欢

转载自blog.csdn.net/m0_51498246/article/details/114089394