Astro: Using Path Alias

September 08, 2025 · minute read

I grabbed this from Starwind UI Docs, to replace relative import with a cleaner one. Add the following to your tsconfig.json file:

tsconfig.json
{
// ...
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
}

That @/ is a path alias, it means that instead of writing long relative imports like:

import Button from "../../../components/ui/Button";

you can just write:

import Button from "@/components/ui/Button";

In this case, @/ maps directly to the src/ folder, making imports easier to maintain.

Comments