import-js/eslint-plugin-import

Webpack config function executing multiple times when using `resolve.alias` and `eslint-import-resolver-webpack`

开放

#1,178 创建于 2018年10月8日

 (1 条评论) (7 个反应) (1 位负责人)JavaScript (1,549 个派生)batch import
help wantedpackage: resolver/webpack

仓库指标

星标
 (5,938 个星标)
PR 合并指标
 (平均合并 138天 22小时) (30 天内合并 3 个 PR)

描述

Description

If webpack.config.js represents config as a function with resolve.alias defined, and when we import/require this alias later in the code while using eslint-import-resolver-webpack for resolving imports in eslint, then webpack config function executing additionally multiple times: one time for each import with alias. I.e. it happens when .eslintrc.js uses eslint-config-airbnb-base and defines wepback import resolver as follows:

module.exports = {
  'extends': ['airbnb-base'],
  'settings': {
    'import/resolver': {
      'webpack': {
        'config': path.join(__dirname, 'webpack.config.js')
      }
    }
  }
};

How to reproduce

  1. Clone a test repo: https://github.com/andreyvolokitin/testcase1
  2. Run npm i && npm run build. The webpack build log in the console will contain multiple additional execute config strings, one for each usage of resolve.alias in src/js/index.js:
test
execute config
execute config
execute config
  1. Remove 'import/resolver' setting from .eslintrc.js and run npm run build again. The build log in console will contain only one instance of execute config:
test
execute config

贡献者指南