🪟 Windows TippsMicrosoft to Hold Surface and Windows Event on October 7(16.09.2026 um 18:25 Uhr)
🪟 Windows TippsNissan bringt seinen Verkaufsschlager Kicks nach Europa(16.09.2026 um 16:34 Uhr)
🪟 Windows ServerBrowser: Firefox 156 bekommt Werbeeinblendungen - Golem.de(16.09.2026 um 17:14 Uhr)
🪟 Windows TippsMicrosoft to Hold Surface and Windows Event on October 7(16.09.2026 um 18:25 Uhr)
🪟 Windows TippsNissan bringt seinen Verkaufsschlager Kicks nach Europa(16.09.2026 um 16:34 Uhr)
🪟 Windows ServerBrowser: Firefox 156 bekommt Werbeeinblendungen - Golem.de(16.09.2026 um 17:14 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 3 Min Lesezeit
0

Say Goodbye to Long Relative Paths with tsconfig Aliases

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

Let’s be real - working with long relative paths can be a pain. Who hasn’t had to deal with something like this?




CODE
import { AuthService } from '../../../services/auth.service';  






It’s messy, hard to read, and even harder to manage when your app grows. But here’s the good news: there’s a way to ditch those long paths and keep your code clean and readable. Enter tsconfig aliases! 🎉









What Are Aliases, and Why Should You Care?



With tsconfig aliases, you can replace those clunky relative paths with short, clean ones that look like below:




CODE
import { AuthService } from '@services/auth.service';  






No more counting ../ or getting lost in nested directories. Aliases make your imports:





  • Readable: Short paths are easier to read and understand.


  • Maintainable: Move files around without breaking half your imports.


  • Scalable: As your project grows, your import statements stay clean.









Setting Up Aliases in Angular



Adding aliases is quick and easy.






Step 1: Update tsconfig.json



In your tsconfig.json, go to compilerOptions and set a baseUrl to point to your src directory. Then, add a paths section to define your aliases:




CODE
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@users/*": ["app/users/*"],
"@products/*": ["app/products/*"]
}
}
}






In this setup:





  • @auth/* maps to src/app/auth/*.


  • @users/* maps to src/app/users/*.


  • @products/* maps to src/app/products/*.









Step 2: Update Your Imports



Now, instead of this:




CODE
import { AuthService } from '../../../auth/auth.service';  






You can use this:




CODE
import { AuthService } from '@services/auth.service';  






Much cleaner, right?









Step 3: Refactor Existing Imports (Optional)



If you already have a bunch of long paths in your app, use your editor’s Find and Replace feature or refactoring tools to update them. Most modern IDEs, like VS Code or WebStorm, can help you automate this.









Bonus: Cleaner Lazy Loading



You can even use aliases for e.g. lazy loading Angular modules:




CODE
const routes: Routes = [  
{
path: 'users',
loadChildren: () => import('@users/user.routes').then(r => r.userRoutes)
}
];






This makes your routes more readable and keeps things consistent.









Why This Matters



Switching to tsconfig aliases isn’t just about making your code look nicer (though that’s a big plus!). It also:




  • Saves time when refactoring - Moving files doesn’t mean endless fixes to import paths.

  • Makes onboarding new team members easier—they’ll instantly understand where imports are coming from.

  • Makes it easier to trace where entities are used, helping you identify and prevent potential circular dependency issues.

  • Helps your project scale without creating a tangled web of relative paths.









Works in Any TypeScript Project



Aliases aren’t limited to any framework - they work anywhere you’re using TypeScript. From React, Angular, Vue to Node, NestJS etc., you can enjoy clean, readable imports across all your projects.






Ready to Clean Things Up?



Take a few minutes to set up aliases in your Angular app, and you’ll never want to go back to those long relative paths. Trust me, your future self will thank you. 🙌

Vollständiger Original-Artikel
Den kompletten Beitrag mit allen Details direkt auf dev.to lesen.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Revolut Data Leak May Trace Back to Compromised Italian Government Accounts
1 Quelle
NIST AI RMF 1.0: The AI Risk Management Framework | UpGuard
1 Quelle
Best Dark Web Monitoring Services for Business | UpGuard
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Say Goodbye to Long Relative Paths with tsconfig Aliases

Thematisch verwandte Begriffe: Goodbye, Long, Relative, Paths · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...