首页 > 解决方案 > 有没有办法覆盖 create-react-app webpack 配置中的 ESLintPlugin 选项?

问题描述

所以我在我的反应应用程序中遇到了 eslint 的问题,我能够在弹出应用程序并ESLintPluginwebpack.config文件中添加一些选项后解决它。

  new ESLintPlugin({
        // Plugin options
        extensions: ['js', 'mjs', 'jsx', 'ts', 'tsx'],
        formatter: require.resolve('react-dev-utils/eslintFormatter'),
        eslintPath: require.resolve('eslint'),
        context: paths.appSrc,
        failOnError: false, <== this one 
        emitWarning: true, <== and this one
        // 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'
            })
          }
        }
      })

我想知道我是否可以做同样的事情,但不必弹出应用程序,react-app-rewired而是使用,我已经有一个config-overrides.js文件

module.exports = function override(webpackConfig) {
  webpackConfig.module.rules.push({
    test: /\.mjs$/,
    include: /node_modules/,
    type: 'javascript/auto',
  });
  return webpackConfig;
};

是否有类似的方法可以访问文件中的 ESLintPlugin 函数webpack.config并通过文件向其添加新选项config-overrides.js

标签: reactjswebpackeslint

解决方案


推荐阅读