反応:create-react-app close eslint

準備オーケー:

最初にreactプロジェクトの構成ファイルを分解する必要があります。
構成ファイルは次のとおりです。configおよびscripts

操作指令:npm run eject  或  yarn eject

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

解体後に問題が発生した場合

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

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

エスリントを閉じる:

1.方法1

configディレクトリでwebpack.config.jsファイルを見つけて、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.方法2

package.jsonのeslintConfigのルールに関するコードを追加します

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

注意:

構成を変更した後は、必ず再起動してください:npmstartまたはyarnstart

おすすめ

転載: blog.csdn.net/m0_51498246/article/details/114089394