update vite compatibility

pull/14/head
Evan You 5 years ago
parent 4b19e6b5a8
commit 9024bc9b41

1
.gitignore vendored

@ -2,6 +2,5 @@
node_modules
dist
TODOs.md
playground
*.log
test/temp

@ -1,5 +1,5 @@
import serialized from '@siteData'
import { hot } from '@hmr'
import { hot } from 'vite/hmr'
import { ref, readonly } from 'vue'
/**

@ -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'

11
lib/shim.d.ts vendored

@ -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)
}
}

@ -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'

@ -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,

@ -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)

@ -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
}
}
}
}

Loading…
Cancel
Save