代码之家  ›  专栏  ›  技术社区  ›  Black Mamba

如何从“@somefolder”导入

  •  -2
  • Black Mamba  · 技术社区  · 6 年前

    import { NGSWUpdateService } from '@ngsw/ngsw-update.service';
    

    开发人员已经能够使用 '@ngsw/ngsw-update.service' 而不是原来的很长的路径 'src/client/app/shared/ngsw/ngsw-update.service' .

    因此,如何实现上述功能,以便我不必从相对较长的路径导入。

    Here's the code.

    1 回复  |  直到 4 年前
        1
  •  1
  •   maxime1992    6 年前

    node_modules

    ngsw-update.service 在这里: node_modules/@ngsw/ngsw-update.service .

    这是最基本的用例,但是您只能通过将这些路径定义为 tsconfig.json (在compilerOptions.paths中,请参阅该文章了解更多信息: https://netbasal.com/sexier-imports-in-typescript-e3c645bdd3c6