首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Webpack - eslint组态

Webpack - eslint组态
EN

Stack Overflow用户
提问于 2021-11-21 22:02:34
回答 1查看 67关注 0票数 0

我使用过babel loader和typescript react,cssModules和eslint (带有更漂亮的)。我已经和webpack一起创建了commonjs库,但是当我开始使用这个库的示例项目时,我得到了像这样的错误。

我没有任何想法来解决这个问题。耽误您时间,实在对不起。

我的WEBPACK配置:

代码语言:javascript
运行
复制
const path = require('path');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const Dotenv = require('dotenv-webpack');

module.exports = {
  mode: 'production',
  entry: ['react-hot-loader', './index.tsx'],
  devtool: 'eval-source-map',
  output: {
    path: path.resolve('dist'),
    filename: 'index.js',
    library: {
      name: 'proba-react-library',
      type: 'commonjs'
    }
  },
  context: path.resolve(__dirname, 'src'),
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'babel-loader',
            options: {
              cacheDirectory: true,
              babelrc: false,
              presets: [
                [
                  '@babel/preset-env',
                  {
                    targets: { browsers: 'last 2 versions' },
                    modules: 'commonjs'
                  } // or whatever your project requires
                ],

                [
                  '@babel/typescript',
                  {
                    configFile: path.resolve(__dirname, 'tsconfig.json'),
                    isTSX: true,
                    allExtensions: true
                  }
                ],
                [
                  '@babel/preset-react',
                  {
                    flow: false,
                    typescript: true
                  }
                ]
              ],
              plugins: [
                // plugin-proposal-decorators is only needed if you're using experimental decorators in TypeScript
                ['@babel/plugin-proposal-decorators', { legacy: true }],
                ['@babel/plugin-proposal-class-properties'],
                'react-hot-loader/babel',
                '@babel/plugin-transform-runtime',
                '@babel/plugin-transform-typescript'
              ]
            }
          }
        ]
      },
      {
        test: /\.(scss|css)$/,
        use: ['style-loader', 'css-loader', 'sass-loader']
      }
    ]
  },
  resolve: {
    extensions: ['.ts', '.tsx', '.js', '.jsx'],
    alias: {
      'react-dom': '@hot-loader/react-dom'
    },
    preferRelative: true,
    modules: [path.resolve(__dirname, 'src'), 'node_modules']
  },
  plugins: [
    new ForkTsCheckerWebpackPlugin({
      typescript: {
        configFile: path.resolve(__dirname, 'tsconfig.json')
      }
    }),
    new Dotenv({
      path: path.resolve(__dirname, '.env')
    })
  ]
};

我的ESLINT配置(和webpack一起在根目录下的.eslintrc中):

代码语言:javascript
运行
复制
{
  "parser": "@babel/eslint-parser",
  "extends": [
    "standard",
    "standard-react",
    "plugin:prettier/recommended",
    "prettier/standard",
    "prettier/react",
    "plugin:@typescript-eslint/eslint-recommended"
  ],
  "env": {
    "node": true
  },
  "parserOptions": {
    "requireConfigFile": false,
    "ecmaVersion": 2020,
    "ecmaFeatures": {
      "legacyDecorators": true,
      "jsx": true
    }
  },
  "settings": {
    "react": {
      "version": "16"
    },
    "import/resolver": {
      "node": {
        "extensions": [".js", ".jsx", ".ts", ".tsx"],
        "moduleDirectory": ["node_modules", "src/"]
      }
    }
  },
  "rules": {
    "space-before-function-parent": 0,
    "react/prop-types": 0,
    "react/jsx-handler-names": 0,
    "no-unused-expressions": "off",
    "react/jsx-fragments": 0,
    "react/no-unused-prop-types": 0,
    "import/export": 0,
    "react-hooks/rules-of-hooks": "error",
    "react-hooks/exhaustive-deps": "warn",
    "no-console": "warn",
    "no-restricted-imports": [
      "error",
      {
        "patterns": [".*"]
      }
    ],
    "import/order": [
      "error",
      {
        "groups": ["builtin", "external", "internal"],
        "pathGroups": [
          {
            "pattern": "react",
            "group": "external",
            "position": "before"
          }
        ],
        "pathGroupsExcludedImportTypes": ["react"]
      }
    ]
  },
  "plugins": [
    "react-hooks",
    "jsx-a11y",
    "react",
    "prettier",
    "@typescript-eslint"
  ]
}
EN

回答 1

Stack Overflow用户

发布于 2021-11-22 04:24:22

也许ignorePatterns会帮你。

您可以在配置文件中使用ignorePatterns告诉ESLint忽略特定的文件和目录。ignorePatterns模式遵循与.eslintignore相同的规则。

代码语言:javascript
运行
复制
// .eslintrc
{
  ...
  ...
  ignorePatterns: ['dist']
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70058959

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档