Skip to content

Commit 4f0c903

Browse files
committed
refactor: simplify client path mapping
1 parent f62f4a4 commit 4f0c903

File tree

6 files changed

+42
-44
lines changed

6 files changed

+42
-44
lines changed

src/client/app/exports.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/client/app/index.html

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/client/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// exports in this file are exposed to themes and md files via 'vitepress'
2+
// so the user can do `import { useRoute, useSiteData } from 'vitepress'`
3+
4+
// generic types
5+
export type { Router, Route } from './app/router'
6+
7+
// theme types
8+
export * from './app/theme'
9+
10+
// composables
11+
export { useRouter, useRoute } from './app/router'
12+
export { useSiteData } from './app/composables/siteData'
13+
export { useSiteDataByRoute } from './app/composables/siteDataByRoute'
14+
export { usePageData } from './app/composables/pageData'
15+
export { useFrontmatter } from './app/composables/frontmatter'
16+
17+
// utilities
18+
export { inBrowser, joinPath } from './app/utils'
19+
20+
// components
21+
export { Content } from './app/components/Content'
22+
23+
import { ComponentOptions } from 'vue'
24+
import _Debug from './app/components/Debug.vue'
25+
const Debug = _Debug as ComponentOptions
26+
export { Debug }
27+
28+
// default theme
29+
export { default as DefaultTheme } from './theme-default'

src/client/tsconfig.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
"lib": ["ESNext", "DOM"],
99
"types": ["vite"],
1010
"paths": {
11-
"/@theme/*": ["theme-default/*"],
12-
"/@default-theme/*": ["theme-default/*"],
1311
"/@shared/*": ["shared/*"],
1412
"/@types/*": ["../../types/*"],
15-
"vitepress": ["app/exports.ts"]
13+
"/@theme/*": ["theme-default/*"],
14+
"vitepress": ["index.ts"]
1615
}
1716
},
1817
"include": [

src/node/alias.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,14 @@ export const DEFAULT_THEME_PATH = path.join(
1717
export const SITE_DATA_ID = '@siteData'
1818
export const SITE_DATA_REQUEST_PATH = '/' + SITE_DATA_ID
1919

20-
// this is a path resolver that is passed to vite
21-
// so that we can resolve custom requests that start with /@app or /@theme
22-
// we also need to map file paths back to their public served paths so that
23-
// vite HMR can send the correct update notifications to the client.
2420
export function resolveAliases(
2521
root: string,
2622
themeDir: string,
2723
userConfig: UserConfig
2824
): AliasOptions {
2925
const paths: Record<string, string> = {
3026
...userConfig.alias,
31-
'/@app': APP_PATH,
3227
'/@theme': themeDir,
33-
'/@default-theme': DEFAULT_THEME_PATH,
3428
'/@shared': SHARED_PATH,
3529
[SITE_DATA_ID]: SITE_DATA_REQUEST_PATH
3630
}
@@ -40,7 +34,10 @@ export function resolveAliases(
4034
find: p,
4135
replacement: paths[p]
4236
})),
43-
{ find: /^vitepress$/, replacement: `${APP_PATH}/exports.js` }
37+
{
38+
find: /^vitepress$/,
39+
replacement: path.join(__dirname, '../client/index')
40+
}
4441
]
4542

4643
let isLinked = false

src/node/plugin.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,16 @@ export function createVitePressPlugin(
7777

7878
configureServer(server) {
7979
// serve our index.html after vite history fallback
80-
const indexPath = `/@fs/${path.join(APP_PATH, 'index.html')}`
8180
return () => {
8281
// @ts-ignore
83-
server.app.use((req, _, next) => {
82+
server.app.use((req, res, next) => {
8483
if (req.url!.endsWith('.html')) {
85-
req.url = indexPath
84+
res.statusCode = 200
85+
res.end(
86+
`<div id="app"></div>\n` +
87+
`<script type="module" src="/@fs/${APP_PATH}/index.js"></script>`
88+
)
89+
return
8690
}
8791
next()
8892
})

0 commit comments

Comments
 (0)