Skip to content

Commit ee3d2bd

Browse files
authored
docs(start): update path aliases config for Vite 8 (#6918)
1 parent 32497be commit ee3d2bd

1 file changed

Lines changed: 27 additions & 9 deletions

File tree

docs/start/framework/react/guide/path-aliases.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,27 @@ By default, TanStack Start does not include path aliases. However, you can easil
2020

2121
In this example, we've defined the path alias `~/*` that maps to the `./src/*` directory. This means that you can now import files from the `src` directory using the `~` prefix.
2222

23-
After updating your `tsconfig.json` file, you'll need to install the `vite-tsconfig-paths` plugin to enable path aliases in your TanStack Start project. You can do this by running the following command:
23+
After updating your `tsconfig.json` file, you'll need to make changes to `vite.config.ts` to ensure that Vite resolves the path aliases correctly.
24+
25+
## Vite 8
26+
27+
Vite 8+ has [built-in support for path aliases](https://vite.dev/config/shared-options#resolve-tsconfigpaths), which is disabled by default. To enable it, simply add the following configuration to your `vite.config.ts` file:
28+
29+
```ts
30+
// vite.config.ts
31+
import { defineConfig } from 'vite'
32+
33+
export default defineConfig({
34+
resolve: {
35+
// This enables built-in support for path aliases defined in tsconfig.json
36+
tsconfigPaths: true,
37+
},
38+
})
39+
```
40+
41+
## Vite 7 and earlier
42+
43+
For Vite 7 and earlier, install the `vite-tsconfig-paths` plugin to enable path aliases in your TanStack Start project. You can do this by running the following command:
2444

2545
```sh
2646
npm install -D vite-tsconfig-paths
@@ -34,14 +54,12 @@ import { defineConfig } from 'vite'
3454
import viteTsConfigPaths from 'vite-tsconfig-paths'
3555

3656
export default defineConfig({
37-
vite: {
38-
plugins: [
39-
// this is the plugin that enables path aliases
40-
viteTsConfigPaths({
41-
projects: ['./tsconfig.json'],
42-
}),
43-
],
44-
},
57+
plugins: [
58+
// this is the plugin that enables path aliases
59+
viteTsConfigPaths({
60+
projects: ['./tsconfig.json'],
61+
}),
62+
],
4563
})
4664
```
4765

0 commit comments

Comments
 (0)