How to integrate paths
of tsconfig with vitepress?
#2746
-
I'm recently confused by My project: .
├── .vitepress
│ ├── config.ts
│ ├── theme
│ ├── components
│ ├── config
│ ├── custom.css
│ └── index.ts
├── docs
│ ├── blog
│ ├── downloader
│ ├── frontend
│ ├── go
│ ├── index.md
│ ├── me
│ ├── open-source
│ ├── public
│ ├── rust
│ └── tool
├── package-lock.json
├── package.json
└── tsconfig.json
export default defineConfig({
// ignore unrelated codes
srcDir: "./docs",
vite: {
server: {
fs: {
allow: ["../.."]
}
}
}
});
{
"compilerOptions": {
/** ignore unrelated codes **/
"paths": {
"@theme/*": [".vitepress/theme/*"],
},
}
}
---
page: true
---
<script setup>
import Home from "@theme/components/Home.vue"
</script>
<Home /> It works very well. But when I make changes: {
"compilerOptions": {
/** ignore unrelated codes **/
"paths": {
"@components/": [".vitepress/theme/components/*"],
},
}
}
---
page: true
---
<script setup>
import Home from "@components/Home.vue"
</script>
<Home /> As a result, there is a bug, which tells me that cannot resolve Why? Is there a black magic behind Any answers will be appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes. something like this should work: // .vitepress/config.ts
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vitepress'
export default defineConfig({
vite: {
resolve: {
alias: {
'@components': fileURLToPath(new URL('./theme/components', import.meta.url))
}
}
}
}) |
Beta Was this translation helpful? Give feedback.
Yes.
@theme
imports have different meaning. For@components/
you need to configure vite aliases along with tsconfig too:something like this should work: