[英]baseUrl in tsconfig.app.json is not overiding the baseUrl in tsconfig.json
在Angular 6中,我正在使用ng generate application,因为我将拥有多个必须共享一些库的应用程序。 使用这种方法,我有这样的文件夹结构:
项目 - > app1-> tsconfig.app.json
项目 - > app2-> tsconfig.app.json
tsconfig.json与projects文件夹处于同一级别
注意 :当我们在Angular 6中使用ng g应用程序时,将创建这样的文件夹结构。
我想在我的组件或服务等中使用相对路径进行这样的导入:
从'src / services / example.service'导入{ExampleService};
而不是必须使用这样的东西:
从'../../../services/example.service'导入{ExampleService};
如何为上面创建的各个应用程序提供此功能?
我的tsconfig.json是这样的
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"downlevelIteration": true,
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
我的tsconfig.app.json是这样的:
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/app",
"types": ["node"]
},
"exclude": ["test.ts", "**/*.spec.ts"]
}
我试过在tsconfig.app.json中这样给出:
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "./",
"outDir": "../../out-tsc/app",
"types": ["node"]
},
"exclude": ["test.ts", "**/*.spec.ts"]
}
但那没用。
我想直接使用src来使用相对路径来消除多级分辨率(../../../)
您应该查看tsconfig.json
paths
。 有了它,你可以这样做:
"compilerOptions": {
"paths": {
"@services/*": [
"src/services/*"
]
}
}
然后,您可以使用以下路径从typescript项目中的任何文件导入:
import { ExampleService } from '@services/example.service';
无需使用@
,您可以随意命名
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.