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,940 顆星)
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

貢獻者指南