如何在eslintrc中手动添加要解析的路径 [英] How to manually add a path to be resolved in eslintrc

查看:697
本文介绍了如何在eslintrc中手动添加要解析的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目 main 中有一个我要解析的文件夹,就像一个模块。例如,从 main / src 导入 main / src / index.js 导入x。这是通过webpack的解析别名配置完成的。

I have a folder in my project main that I am resolving like a module. For instance import x from 'main/src' imports main/src/index.js. This is done through webpack's resolve alias configuration.

我遇到的一个问题是通过eslint消除了错误。我知道eslint提供了一个webpack解析插件,但是,我一直无法正常工作。我怀疑是因为我在webpack 2上,并且在我的webpack配置文件中使用了es6。

An issue I am having is getting rid of the errors via eslint. I know eslint provides a webpack resolve plugin, however, I've been having trouble getting it to work. I suspect it is because I am on webpack 2 and using es6 in my webpack config files.

是否有手动方式来编写解决此问题的解决方法eslint吗?

Is there a manual way to write a resolve setting that fixes this problem for my eslint?

我见过的唯一其他破解方法是使用 import / core-modules ,但是然后我必须列出子目录树中的每个文件夹 main / src / bar main / src / foo

The only other hack I've seen work is using import/core-modules but then I have to list out every folder in the subdirectory tree main/src/bar, main/src/foo. This would not be ideal.

推荐答案

我认为下面的链接可以为您提供帮助。
您可以使用config添加解析目录。

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

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

例如,如果您想解决 src / ,您可以在 .eslintrc 上写如下。

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

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

然后从src目录解析ESLint。
您可以通过编写 const moge = require('hoge / moge'); src / hoge / moge.js c $ c>和ESLint知道。

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

这篇关于如何在eslintrc中手动添加要解析的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆