由于我已将应用程序移动到角度项目中,所以在处理别名时遇到问题
我的进口产品都不适用于我的"@应用程序";别名
mainApp
│ package.json
│ tsconfig.json
│ angular.json
│
└───projects
│
└───my-project (That I need the aliasing for)
│ tsconfig.app.json
│
└───src
│
└───app
当我使用:
import { MyService } from '@app/shared/services/my.service';
我收到错误
在我的tsconfig.app.json:
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/app",
"types": []
},
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"baseUrl": "./",
"paths": {
"@app/*": ["src/app/*"],
"@env/*": ["environments/*"]
},
"include": [
"src/**/*.d.ts"
]
}
我试过
"@app/*": ["projects/my-project/src/app/*"],
我还更新了我的主tsconfig.json:
....
"baseUrl": "./",
"paths": {
"@app/*": ["src/app/*"],
"@env/*": ["environments/*"]
},
...
然后为项目服务:
ng serve --project my-project
问题是因为我的路径对象在compilerOptions
对象之外,所以:
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@app/*": ["projects/my-/src/app/*"],
"@env/*": ["environments/*"]
},
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"module": "es2020",
"lib": [
"es2018",
"dom"
]
}
成功了!!!而不是
"compilerOptions": {
.......
},"paths": {
"@app/*": ["projects/my-project/src/app/*"],
"@env/*": ["environments/*"]
}