[英]baseUrl in tsconfig.app.json is not overiding the baseUrl in tsconfig.json
In Angular 6, I'm using ng generate application as I will have more than one application which has to share some libraries. 在Angular 6中,我正在使用ng generate application,因为我将拥有多个必须共享一些库的应用程序。 With this approach, I have folder structure like this:
使用这种方法,我有这样的文件夹结构:
projects->app1->tsconfig.app.json
项目 - > app1-> tsconfig.app.json
projects->app2->tsconfig.app.json
项目 - > app2-> tsconfig.app.json
And the tsconfig.json is in the same level as projects folder tsconfig.json与projects文件夹处于同一级别
Note : Folder structure like this will be created when we use ng g application in Angular 6. 注意 :当我们在Angular 6中使用ng g应用程序时,将创建这样的文件夹结构。
I want to use relative paths in my components or services etc for imports like this: 我想在我的组件或服务等中使用相对路径进行这样的导入:
import { ExampleService } from 'src/services/example.service';
从'src / services / example.service'导入{ExampleService};
instead of having to use it something like this: 而不是必须使用这样的东西:
import { ExampleService } from '../../../services/example.service';
从'../../../services/example.service'导入{ExampleService};
How can I provide this features for the individual applications that are created like mentioned above? 如何为上面创建的各个应用程序提供此功能?
My tsconfig.json is like this 我的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"
]
}
}
And my tsconfig.app.json is like this: 我的tsconfig.app.json是这样的:
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/app",
"types": ["node"]
},
"exclude": ["test.ts", "**/*.spec.ts"]
}
I have tried giving like this in the tsconfig.app.json: 我试过在tsconfig.app.json中这样给出:
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "./",
"outDir": "../../out-tsc/app",
"types": ["node"]
},
"exclude": ["test.ts", "**/*.spec.ts"]
}
But that didn't work. 但那没用。
I want to use the relative paths by using src directly to eliminate the multiple level resolution (../../../)
我想直接使用src来使用相对路径来消除多级分辨率
(../../../)
You should have a look at the paths
compilerOption from tsconfig.json
. 您应该查看
tsconfig.json
paths
。 With it you can do this for instance: 有了它,你可以这样做:
"compilerOptions": {
"paths": {
"@services/*": [
"src/services/*"
]
}
}
You can then import from any file inside your typescript project using this path: 然后,您可以使用以下路径从typescript项目中的任何文件导入:
import { ExampleService } from '@services/example.service';
No need to use @
, you can name it whatever you like 无需使用
@
,您可以随意命名
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.