update vite compatibility

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

1
.gitignore vendored

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

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

@ -6,7 +6,7 @@ import { pageDataSymbol } from './composables/pageData'
import { Content } from './components/Content' import { Content } from './components/Content'
import Debug from './components/Debug.vue' import Debug from './components/Debug.vue'
import Theme from '/@theme/index' import Theme from '/@theme/index'
import { hot } from '@hmr' import { hot } from 'vite/hmr'
const inBrowser = typeof window !== 'undefined' const inBrowser = typeof window !== 'undefined'

11
lib/shim.d.ts vendored

@ -1,19 +1,12 @@
declare const __DEV__: boolean declare const __DEV__: boolean
declare module "*.vue" { declare module '*.vue' {
import { ComponentOptions } from 'vue' import { ComponentOptions } from 'vue'
const comp: ComponentOptions const comp: ComponentOptions
export default comp export default comp
} }
declare module "@siteData" { declare module '@siteData' {
const data: string const data: string
export default data 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 fs from 'fs-extra'
import { bundle } from './bundle' import { bundle } from './bundle'
import { BuildOptions as ViteBuildOptions } from 'vite' import { BuildConfig as ViteBuildOptions } from 'vite'
import { resolveConfig } from '../config' import { resolveConfig } from '../config'
import { renderPage } from './render' import { renderPage } from './render'

@ -9,7 +9,7 @@ import { createMarkdownToVueRenderFn } from '../markdownToVue'
import { import {
build, build,
ssrBuild, ssrBuild,
BuildOptions as ViteBuildOptions, BuildConfig as ViteBuildOptions,
BuildResult BuildResult
} from 'vite' } from 'vite'
@ -70,7 +70,6 @@ export async function bundle(
const { rollupInputOptions = {}, rollupOutputOptions = {} } = options const { rollupInputOptions = {}, rollupOutputOptions = {} } = options
const viteOptions: ViteBuildOptions = { const viteOptions: ViteBuildOptions = {
...options, ...options,
cdn: false,
resolvers: [resolver], resolvers: [resolver],
outDir: config.outDir, outDir: config.outDir,
assetsDir: ASSETS_DIR, assetsDir: ASSETS_DIR,

@ -2,8 +2,8 @@ import path from 'path'
import { import {
createServer as createViteServer, createServer as createViteServer,
cachedRead, cachedRead,
Plugin, ServerConfig,
ServerConfig ServerPlugin
} from 'vite' } from 'vite'
import { resolveConfig, SiteConfig, resolveSiteData } from './config' import { resolveConfig, SiteConfig, resolveSiteData } from './config'
import { createMarkdownToVueRenderFn } from './markdownToVue' import { createMarkdownToVueRenderFn } from './markdownToVue'
@ -16,7 +16,7 @@ function createVitePressPlugin({
themeDir, themeDir,
configPath, configPath,
site: initialSiteData site: initialSiteData
}: SiteConfig): Plugin { }: SiteConfig): ServerPlugin {
return ({ app, root, watcher, resolver }) => { return ({ app, root, watcher, resolver }) => {
const markdownToVue = createMarkdownToVueRenderFn(root) const markdownToVue = createMarkdownToVueRenderFn(root)

@ -1,11 +1,15 @@
import path from 'path' import path from 'path'
import { Resolver } from "vite" import { Resolver } from 'vite'
// built ts files are placed into /dist // built ts files are placed into /dist
export const APP_PATH = path.join(__dirname, '../../lib/app') export const APP_PATH = path.join(__dirname, '../../lib/app')
// special virtual file // 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 // this is a path resolver that is passed to vite
// so that we can resolve custom requests that start with /@app or /@theme // 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 return SITE_DATA_REQUEST_PATH
} }
}, },
idToRequest(id) { alias(id) {
if (id === 'vitepress') { if (id === 'vitepress') {
return '/@app/exports.js' return '/@app/exports.js'
} }
if (id === SITE_DATA_ID) {
return SITE_DATA_REQUEST_PATH
}
} }
} }
} }

Loading…
Cancel
Save