Avoiding relative paths in Angular CLI

后端 未结 7 1054
-上瘾入骨i
-上瘾入骨i 2020-11-30 20:54

I\'m using the latest Angular CLI, and I\'ve created a custom components folder which is a collection of all components.

For example, TextInputComponent

7条回答
  •  抹茶落季
    2020-11-30 21:22

    Above all answer correct, but after struggling by searching over internet n trying to understand what exactly problem and trying different troubleshooting option, I came to know baseUrl and Path how works toghether

    If you use baseUrl:"." like below it works in VScode but not while compiling

    {
      "compileOnSave": false,
      "compilerOptions": {
        "outDir": "./dist/out-tsc",
        "baseUrl": ".",
        "paths": {
          "@myproject/*": ["src/app/*"]
        }    
    }
    

    As per my understanding and my working app and checked in angular aio code, I suggest use as baseUrl:"src" like below

    {
      "compileOnSave": false,
      "compilerOptions": {
        "outDir": "./dist/out-tsc",
        "baseUrl": "src",
        "paths": {
          "@myproject/*": ["app/*"],
          "testing/*": ["testing/*"]
        }    
    }
    

    By having base url as source(src directory), compiler properly resolves modules.

    I hope this helps to people resolve this kind of issue.

提交回复
热议问题