简体   繁体   English

Angular/Typescript tsconfig.json 配置多个路径的路径别名

[英]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.

相关问题 Angular 在 tsconfig.json 中声明的库路径别名不起作用:找不到模块:错误:无法解析 - Angular Library paths alias declared in tsconfig.json not working: Module not found: Error: Can't resolve Angular Typescript - exclude在tsconfig.json中不起作用 - Angular Typescript - exclude is not working in tsconfig.json 如何在tsconfig.json文件中为外部库配置路径属性 - How to configure paths property in tsconfig.json file for external libraries 使用tsconfig.json的Visual Studio 2015,Typescript和angular2 - Visual Studio 2015, Typescript and angular2 with tsconfig.json Angular 9 tsconfig.json & tsconfig.app.json 路径未按预期工作 - Angular 9 tsconfig.json & tsconfig.app.json paths are not working as expected 在 tsconfig.json 上使用路径无法使用 angular 解析 - using path on tsconfig.json doesn't resolve using angular 路径在tsconfig.json中无法正常工作 - paths is not working in tsconfig.json as expected 无法使用 tsconfig.json 缩短导入路径 - Cannot shorten import paths with tsconfig.json 无法识别 tsconfig.json 中的 Visual Studio 2017 Typescript baseUrl/paths - Visual Studio 2017 Typescript baseUrl/paths in tsconfig.json not being recognized 在配置文件“ tsconfig.json”中找不到输入。 指定的“包含”路径在Angular 6中 - No inputs were found in config file 'tsconfig.json'. Specified 'include' paths were in Angular 6
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM