简体   繁体   English

tsconfig.json 路径模式

[英]tsconfig.json path pattern

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.请注意,在上一个示例中,指定“src”文件夹已被跳过。 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此外,'myresource' 将更改为匹配该路径中的任何文件夹('myresource'、'myresource1'、'myresource2' 等),所以我想知道是否有任何不需要我添加的解决方案tsconfig.json 的“路径”object 中的每个特定文件夹

You can do this in your tsconfig.json ( example ):您可以在tsconfig.json示例)中执行此操作:

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

You can also customize the paths for your needs.您还可以根据需要自定义路径。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM