Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

short way to import components and modules

I used @angular/cli to create my app. when my app size increases it becomes quite difficult to mention the paths of imports for components/modules/scss used

for example, if a component structure went deep enough. to import we have to mention import {something} from '../../../../someComponent' goes on.

Is there a way we can define them somewhere like a schema can be defined

for example:

Schema.json

{
"someComponent":"../../../../someComponent',
 "otherComponent:"../../"
}

and we can directly import as import {someComponent} from 'someComponent; and can be imported easily anywhere

Is there any method like this.

like image 789
Sibiraj Avatar asked Oct 16 '25 00:10

Sibiraj


1 Answers

paths can be added in tsconfig.json:

{
  "compilerOptions": {
    ...,  
    "paths": {
      ...,
      "@app/*": ["app/*"],
      "@components/*": ["components/*"]
    }
  }
}

Then import absolutely from app/ or components/ instead of relative to the current file:

import {TextInputConfiguration} from "@components/configurations";
like image 56
Sibiraj Avatar answered Oct 18 '25 15:10

Sibiraj