【发布时间】:2019-05-13 20:27:19
【问题描述】:
在 Angular 6 中,我使用 ng generate application,因为我将拥有多个必须共享一些库的应用程序。使用这种方法,我的文件夹结构如下:
项目->app1->tsconfig.app.json
项目->app2->tsconfig.app.json
并且 tsconfig.json 与 projects 文件夹处于同一级别
注意:当我们在 Angular 6 中使用 ng g application 时,会创建这样的文件夹结构。
我想在我的组件或服务等中使用相对路径来进行这样的导入:
从 '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来消除多级分辨率(../../../)
【问题讨论】:
标签: angular angular6 angular7 typescript2.0