Skip to content

Commit b2a8c5c

Browse files
Mlocik97benmccann
andauthored
Update 50-aliases.md (#5036)
* Update 50-aliases.md * Update documentation/faq/50-aliases.md Co-authored-by: Ben McCann <[email protected]> * Update documentation/faq/50-aliases.md Co-authored-by: Ben McCann <[email protected]> Co-authored-by: Ben McCann <[email protected]>
1 parent 4f3b1db commit b2a8c5c

File tree

1 file changed

+2
-36
lines changed

1 file changed

+2
-36
lines changed

documentation/faq/50-aliases.md

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,6 @@
22
title: How do I setup a path alias?
33
---
44

5-
First, you need to add it to the Vite configuration. In `svelte.config.js` add [`vite.resolve.alias`](https://vitejs.dev/config/#resolve-alias):
5+
Aliases can be set in `svelte.config.js` as described in the [`configuration`](/docs/configuration#alias) docs.
66

7-
```js
8-
/// file: svelte.config.js
9-
// @filename: ambient.d.ts
10-
declare module 'path';
11-
12-
// @filename: index.js
13-
import path from 'path';
14-
15-
/** @type {import('@sveltejs/kit').Config} */
16-
const config = {
17-
kit: {
18-
vite: {
19-
resolve: {
20-
alias: {
21-
$utils: path.resolve('./src/utils')
22-
}
23-
}
24-
}
25-
}
26-
};
27-
28-
export default config;
29-
```
30-
31-
Then, to make TypeScript aware of the alias, add it to `tsconfig.json` (for TypeScript users) or `jsconfig.json`:
32-
33-
```json
34-
{
35-
"compilerOptions": {
36-
"paths": {
37-
"$utils/*": ["src/utils/*"]
38-
}
39-
}
40-
}
41-
```
7+
Then run `npm run sync` or `npm run dev` (which will execute `sync`). SvelteKit will automatically generate the required alias configuration in `jsconfig.json` or `tsconfig.json`.

0 commit comments

Comments
 (0)