react: create-react-app close eslint

Ready to work:

You need to deconstruct the configuration file of the react project first. The
configuration files are: config and scripts

操作指令:npm run eject  或  yarn eject

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

If you encounter problems after deconstruction

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

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

Close eslint:

1. Method One

Find the webpack.config.js file in the config directory to comment on the import and rules of eslint

	!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. Method two

Add the code about rules in eslintConfig in package.json

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

note:

Be sure to restart after changing the configuration: npm start or yarn start

Guess you like

Origin blog.csdn.net/m0_51498246/article/details/114089394