[英]Angular/Typescript tsconfig.json configure path alias with multiple paths
I configured some path alias in my tsconfig.json
and they works fine:我在
tsconfig.json
配置了一些路径别名,它们工作正常:
"paths": {
"@app/models": ["src/app/app.models"],
"@app/routing": ["src/app/app-routing.module"],
"@app/routing/*": ["src/app/routing/*"]
}
What I need now is to configure another path alias with multiple paths.我现在需要的是用多个路径配置另一个路径别名。 Should be something similar to this:
应该是类似的东西:
"@app/ab": ["src/app/test-a/a", "src/app/test-b/b"]
The problem is when I import from @app/ab
because I can see only classes declared in src/app/test-a/a
.问题是当我从
@app/ab
导入时,因为我只能看到src/app/test-a/a
声明的类。 Is there a possibile solution to achieve this?有没有可能的解决方案来实现这一目标?
You could make an 'index.ts' file where you export "src/app/test-a/a", "src/app/test-b/b".您可以制作一个“index.ts”文件,在其中导出“src/app/test-a/a”、“src/app/test-b/b”。 And then refer to the index file.
然后参考索引文件。
// src/app/test-index.ts // src/app/test-index.ts
export * from 'src/app/test-a/a';
export * from 'src/app/test-b/b';
// tsconfig.json // tsconfig.json
...
"@app/ab": ["src/app/test-index.ts"]
...
OR或者
Add the folders instead of the files添加文件夹而不是文件
"@app/ab/*": ["src/app/test-a/*", "src/app/test-b/*"]
But then everything within 'test-a' and 'test-b' will also be exposed via that path.但随后 'test-a' 和 'test-b' 中的所有内容也将通过该路径公开。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.