如何使用 Angular/.NET Core/tsconfig 指定路径?

How Do I Specify Paths with Angular/.NET Core/tsconfig?

我正在尝试清理我的 angular 应用程序中的路径,该应用程序是使用 dotnet new angular 构建的。我运行这个命令的时候在根目录下有一个tsconfig.json

相关内容如下:

{
  "compilerOptions": {
    ...
    "baseUrl": ".",
    "paths": {
      "@models": ["ClientApp/app/models/*"]
    }
  },
  ...
}

现在,在我的服务中:

import { Person } from '@models/person.model';

不幸的是,我收到错误消息:找不到模块@models/person.model

在 .net core/angular 应用程序中使用 tsconfig.json link 路径的正确方法是什么?

更新

我查了一些资料暗示这和webpack有关。它建议添加:

const { TsConfigPathsPlugin } = require('awesome-typescript-loader');

resolve: {
  plugins: [
    new TsConfigPathsPlugin(/* { configFileName, compiler } */)
  ]
}

我没有看到任何关于为编译器提供什么值的信息。我认为它会默认为 tsc。另外,一些示例将 configFileName 显示为路径,而其他示例仅显示为文件名。这是我输入的内容:

new TsConfigPathsPlugin({ configFileName: './tsconfig.json'})

在 angular 项目的基础上(假设您使用了 angular-cli)basePath 应该是 src 而不是 . 因为它存在上一层。 你的其余部分应该工作。