Description
Describe the problem
Could have sworn we already had an issue for this. Anyway. Custom aliases are a tiny bit confusing at the moment, because you have to declare them in both the Vite config and the TypeScript config, using very different approaches:
const config = {
kit: {
vite: {
resolve: {
alias: {
$utils: path.resolve('src/utils')
}
}
}
}
};
{
"compilerOptions": {
"paths": {
"$utils": ["src/utils"],
"$utils/*": ["src/utils/*"]
}
}
}
And because of the tsconfig merging logic, as soon as you declare custom aliases you have to take care to also declare the $lib
alias...
{
"compilerOptions": {
"paths": {
+ "$lib": ["src/lib"],
+ "$lib/*": ["src/lib/*"],
"$utils": ["src/utils"],
"$utils/*": ["src/utils/*"]
}
}
}
...even if you're not using it, which annoys some people.
Describe the proposed solution
const config = {
kit: {
alias: {
$utils: 'src/utils'
}
}
};
For Vite, we add [key]: path.resolve(project_root, value)
.
For TypeScript, we add [key]: value, [key + '/*']: value + '/*'
.
People still have the ability to use the more complex options if they so choose, but this takes care of common cases.
Alternatives considered
Not doing this, on the grounds that overusing aliases is problematic.
Importance
nice to have
Additional Information
No response