diff --git a/.gitignore b/.gitignore index 9b1a20c9..763accc2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,5 @@ node_modules dist TODOs.md -playground *.log test/temp diff --git a/lib/app/composables/siteData.js b/lib/app/composables/siteData.js index b3d171b3..ad3b6f39 100644 --- a/lib/app/composables/siteData.js +++ b/lib/app/composables/siteData.js @@ -1,5 +1,5 @@ import serialized from '@siteData' -import { hot } from '@hmr' +import { hot } from 'vite/hmr' import { ref, readonly } from 'vue' /** diff --git a/lib/app/index.js b/lib/app/index.js index 2a141f9e..825503f3 100644 --- a/lib/app/index.js +++ b/lib/app/index.js @@ -6,7 +6,7 @@ import { pageDataSymbol } from './composables/pageData' import { Content } from './components/Content' import Debug from './components/Debug.vue' import Theme from '/@theme/index' -import { hot } from '@hmr' +import { hot } from 'vite/hmr' const inBrowser = typeof window !== 'undefined' diff --git a/lib/shim.d.ts b/lib/shim.d.ts index 8a94277a..09299509 100644 --- a/lib/shim.d.ts +++ b/lib/shim.d.ts @@ -1,19 +1,12 @@ declare const __DEV__: boolean -declare module "*.vue" { +declare module '*.vue' { import { ComponentOptions } from 'vue' const comp: ComponentOptions export default comp } -declare module "@siteData" { +declare module '@siteData' { const data: string export default data } - -declare module "@hmr" { - export declare const hot: { - accept(path: string, cb: (module: any) => void) - on(event: string, cb: (data: any) => void) - } -} diff --git a/src/build/build.ts b/src/build/build.ts index 5ff1a2b9..00610b9b 100644 --- a/src/build/build.ts +++ b/src/build/build.ts @@ -1,6 +1,6 @@ import fs from 'fs-extra' import { bundle } from './bundle' -import { BuildOptions as ViteBuildOptions } from 'vite' +import { BuildConfig as ViteBuildOptions } from 'vite' import { resolveConfig } from '../config' import { renderPage } from './render' diff --git a/src/build/bundle.ts b/src/build/bundle.ts index 4b46b103..852bce2b 100644 --- a/src/build/bundle.ts +++ b/src/build/bundle.ts @@ -9,7 +9,7 @@ import { createMarkdownToVueRenderFn } from '../markdownToVue' import { build, ssrBuild, - BuildOptions as ViteBuildOptions, + BuildConfig as ViteBuildOptions, BuildResult } from 'vite' @@ -70,7 +70,6 @@ export async function bundle( const { rollupInputOptions = {}, rollupOutputOptions = {} } = options const viteOptions: ViteBuildOptions = { ...options, - cdn: false, resolvers: [resolver], outDir: config.outDir, assetsDir: ASSETS_DIR, diff --git a/src/server.ts b/src/server.ts index a3fc0198..6674cbd2 100644 --- a/src/server.ts +++ b/src/server.ts @@ -2,8 +2,8 @@ import path from 'path' import { createServer as createViteServer, cachedRead, - Plugin, - ServerConfig + ServerConfig, + ServerPlugin } from 'vite' import { resolveConfig, SiteConfig, resolveSiteData } from './config' import { createMarkdownToVueRenderFn } from './markdownToVue' @@ -16,7 +16,7 @@ function createVitePressPlugin({ themeDir, configPath, site: initialSiteData -}: SiteConfig): Plugin { +}: SiteConfig): ServerPlugin { return ({ app, root, watcher, resolver }) => { const markdownToVue = createMarkdownToVueRenderFn(root) diff --git a/src/utils/pathResolver.ts b/src/utils/pathResolver.ts index e7b5e98b..2b1be20e 100644 --- a/src/utils/pathResolver.ts +++ b/src/utils/pathResolver.ts @@ -1,11 +1,15 @@ import path from 'path' -import { Resolver } from "vite" +import { Resolver } from 'vite' // built ts files are placed into /dist export const APP_PATH = path.join(__dirname, '../../lib/app') // special virtual file -export const SITE_DATA_REQUEST_PATH = '/@siteData' +// we can't directly import '/@siteData' becase +// - it's not an actual file so we can't use tsconfig paths to redirect it +// - TS doesn't allow shimming a module that starts with '/' +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 @@ -35,10 +39,13 @@ export function createResolver(themeDir: string): Resolver { return SITE_DATA_REQUEST_PATH } }, - idToRequest(id) { + alias(id) { if (id === 'vitepress') { return '/@app/exports.js' } + if (id === SITE_DATA_ID) { + return SITE_DATA_REQUEST_PATH + } } } }