How to manually add a path to be resolved in eslintrc

ε祈祈猫儿з 提交于 2019-11-29 22:10:36

I think the link below helps you. You can add resolving directories by using config.

https://github.com/benmosher/eslint-plugin-import#resolvers

For example, if you want to resolve src/, you can write like below on .eslintrc.

{
  "settings": {
    "import/resolver": {
      "node": {
        "paths": ["src"]
      }
    }
  }
}

Then ESLint resolve from src directory. You can require src/hoge/moge.js by writing const moge = require('hoge/moge'); and ESLint knows it.

Too late to see this question. Actually, there is already a resolver named eslint-import-resolver-alias that implements this functionality with the below setting.

{
  settings: {
    'import/resolver': {
      'alias': [
        ['main/src', './main/src']
       ]
     }
  }
}

I had the same issue with webpack. I installed eslint-import-resolver-webpack and updated .eslintrc thusly

{
    "settings": {
        "import/resolver": "webpack"
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!