diff --git a/src/client/app/exports.ts b/src/client/app/exports.ts deleted file mode 100644 index 6012598b..00000000 --- a/src/client/app/exports.ts +++ /dev/null @@ -1,29 +0,0 @@ -// exports in this file are exposed to themes and md files via 'vitepress' -// so the user can do `import { useRoute, useSiteData } from 'vitepress'` - -// generic types -export type { Router, Route } from './router' - -// theme types -export * from './theme' - -// composables -export { useRouter, useRoute } from './router' -export { useSiteData } from './composables/siteData' -export { useSiteDataByRoute } from './composables/siteDataByRoute' -export { usePageData } from './composables/pageData' -export { useFrontmatter } from './composables/frontmatter' - -// utilities -export { inBrowser, joinPath } from './utils' - -// components -export { Content } from './components/Content' - -import { ComponentOptions } from 'vue' -import _Debug from './components/Debug.vue' -const Debug = _Debug as ComponentOptions -export { Debug } - -// default theme -export { default as DefaultTheme } from '../theme-default' diff --git a/src/client/app/index.html b/src/client/app/index.html deleted file mode 100644 index 69e2efbb..00000000 --- a/src/client/app/index.html +++ /dev/null @@ -1,2 +0,0 @@ -
- diff --git a/src/client/index.ts b/src/client/index.ts new file mode 100644 index 00000000..8dc04483 --- /dev/null +++ b/src/client/index.ts @@ -0,0 +1,29 @@ +// exports in this file are exposed to themes and md files via 'vitepress' +// so the user can do `import { useRoute, useSiteData } from 'vitepress'` + +// generic types +export type { Router, Route } from './app/router' + +// theme types +export * from './app/theme' + +// composables +export { useRouter, useRoute } from './app/router' +export { useSiteData } from './app/composables/siteData' +export { useSiteDataByRoute } from './app/composables/siteDataByRoute' +export { usePageData } from './app/composables/pageData' +export { useFrontmatter } from './app/composables/frontmatter' + +// utilities +export { inBrowser, joinPath } from './app/utils' + +// components +export { Content } from './app/components/Content' + +import { ComponentOptions } from 'vue' +import _Debug from './app/components/Debug.vue' +const Debug = _Debug as ComponentOptions +export { Debug } + +// default theme +export { default as DefaultTheme } from './theme-default' diff --git a/src/client/tsconfig.json b/src/client/tsconfig.json index a2762775..08160422 100644 --- a/src/client/tsconfig.json +++ b/src/client/tsconfig.json @@ -8,11 +8,10 @@ "lib": ["ESNext", "DOM"], "types": ["vite"], "paths": { - "/@theme/*": ["theme-default/*"], - "/@default-theme/*": ["theme-default/*"], "/@shared/*": ["shared/*"], "/@types/*": ["../../types/*"], - "vitepress": ["app/exports.ts"] + "/@theme/*": ["theme-default/*"], + "vitepress": ["index.ts"] } }, "include": [ diff --git a/src/node/alias.ts b/src/node/alias.ts index 50f59a45..add67ee8 100644 --- a/src/node/alias.ts +++ b/src/node/alias.ts @@ -17,10 +17,6 @@ export const DEFAULT_THEME_PATH = path.join( export const SITE_DATA_ID = '@siteData' export const SITE_DATA_REQUEST_PATH = '/' + SITE_DATA_ID -// this is a path resolver that is passed to vite -// so that we can resolve custom requests that start with /@app or /@theme -// we also need to map file paths back to their public served paths so that -// vite HMR can send the correct update notifications to the client. export function resolveAliases( root: string, themeDir: string, @@ -28,9 +24,7 @@ export function resolveAliases( ): AliasOptions { const paths: Record = { ...userConfig.alias, - '/@app': APP_PATH, '/@theme': themeDir, - '/@default-theme': DEFAULT_THEME_PATH, '/@shared': SHARED_PATH, [SITE_DATA_ID]: SITE_DATA_REQUEST_PATH } @@ -40,7 +34,10 @@ export function resolveAliases( find: p, replacement: paths[p] })), - { find: /^vitepress$/, replacement: `${APP_PATH}/exports.js` } + { + find: /^vitepress$/, + replacement: path.join(__dirname, '../client/index') + } ] let isLinked = false diff --git a/src/node/plugin.ts b/src/node/plugin.ts index a32d6b9c..21d53f33 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -77,12 +77,16 @@ export function createVitePressPlugin( configureServer(server) { // serve our index.html after vite history fallback - const indexPath = `/@fs/${path.join(APP_PATH, 'index.html')}` return () => { // @ts-ignore - server.app.use((req, _, next) => { + server.app.use((req, res, next) => { if (req.url!.endsWith('.html')) { - req.url = indexPath + res.statusCode = 200 + res.end( + `
\n` + + `` + ) + return } next() })