tsconfig.json 路径模式

发布于 2025-01-16 08:35:40 字数 368 浏览 3 评论 0原文

有什么方法可以按路径模式包含文件吗?例如,我目前正在我的脚本中执行此操作:

import '../../../../myresource/src/shared/my-interface'

但是,我想简单地使用这个:

import '@myresource/shared/my-interface'

请注意,在最后一个示例中,已跳过指定“src”文件夹。另外,“myresource”将更改为匹配该路径中的任何文件夹(“myresource”、“myresource1”、“myresource2”等),所以我想知道是否有任何解决方案不需要我添加tsconfig.json 的“paths”对象内的每个特定文件夹

Is there any way to include files by path pattern? For example, I am currently doing this in my scripts:

import '../../../../myresource/src/shared/my-interface'

However, I would like to simply use this:

import '@myresource/shared/my-interface'

Notice that in the last example, specifying the 'src' folder has been skipped. Also, 'myresource' would be changed to match any folder at that path ('myresource', 'myresource1', 'myresource2', etc..), so I would like to know if there's any solution which would not require me to add each specific folder inside the 'paths' object of the tsconfig.json

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北音执念 2025-01-23 08:35:40

您可以在 tsconfig.json 中执行此操作(示例):

{
  "compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "@*": ["*"]
    }
  }
}

您还可以根据需要自定义路径。

{
  "compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "@*": ["*", "dir1/*"]
    }
  }
}

You can do this in your tsconfig.json (example):

{
  "compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "@*": ["*"]
    }
  }
}

You can also customize the paths for your needs.

{
  "compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "@*": ["*", "dir1/*"]
    }
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文