集中管理导入路径的地方

时间:2017-01-09 10:28:15

标签: angular

我正在寻找一种在角度2.0中管理导入路径的方法。我会先配置一次,然后将其称为变量。 e.g。

import { ProductService } from Paths.Product.ProductService;

这允许我移动类的文件夹位置,并在应用程序中进行另一个更改。

是这样的。

由于

1 个答案:

答案 0 :(得分:2)

您可以使用paths中的tsconfig.json媒体资源:

{
  "compilerOptions": {
    ...
    "baseUrl": ".",
    "paths": {
      "@Product/*": ["./path/to/product/*"]
    },
    "rootDir": "."
  }
}

然后您可以导入/path/to/product文件夹中的任何文件,如:

import { ProductService } from '@Product/service';

如果你想改变你的路径,你只需要在tsconfig中编辑它

相关问题