还有另一种方法-一种更清晰的方法来指定导入路径吗?我指的是圆点和正斜杠
我有这样的东西:
import { Product } from '../../../../../../@core/model/v2/domain/product';
import { ConfigService } from '../../../../../../@core/data/config.service';
import { ProductMappingContainer } from '../../../../../../@core/model/v2/dto/productMappingContainer';
import { AddProductModalSource } from '../../../../../../@core/model/v2/types/addProductModalSource';
答案 0 :(得分:1)
打字稿编译器允许路径映射。
在tsconfig.json文件中,您可以添加baseurl:
{
"compilerOptions": {
...
"baseUrl": "./src",
"paths": {
"@shared/*":["app/modules/shared/*"],
"@core/*":["app/modules/core/*"]
}
...
}
}
,然后在您的导入中:
import { MyComponent } from '@shared/components/mycomponent'
此内容取自此medium-itnext article