如何让 ESLint 识别 Docusaurus 别名?

How can I get ESLint to recognize Docusaurus aliases?

情况

我正在处理 Docusaurus project which will include some custom components. I'd like to also use ESLint, and in particular the AirBnB 配置。

当我 运行 在最初生成的 Docusaurus 项目上使用 linter 时,我遇到了一些错误(并不意外),但这三个让我停下来:

src/pages/index.jsx
  3:20  error  Unable to resolve path to module '@theme/Layout'                     import/no-unresolved
  4:18  error  Unable to resolve path to module '@docusaurus/Link'                  import/no-unresolved
  5:34  error  Unable to resolve path to module '@docusaurus/useDocusaurusContext'  import/no-unresolved

我怀疑这些模块是 Docusaurus 知道如何解析的别名,但 ESLint 不知道。

问题

我想避免禁用 import/no-unresolved

有没有方便的方法让 ESLint 识别(并解析)来自 Docusaurus 的别名?

@theme@docusaurus 等不是实际路径。它们是 webpack 的别名。为了防止 ESLint 被这些绊倒,你可以在 ESLint 设置中忽略那些

"import/no-unresolved": [ 2, {"ignore": ["^@theme", "^@docusaurus", "^@site"]}],