|
|
@ -1,7 +1,8 @@
|
|
|
|
import path from 'path'
|
|
|
|
import path from 'path'
|
|
|
|
|
|
|
|
import c from 'picocolors'
|
|
|
|
import { defineConfig, mergeConfig, Plugin, ResolvedConfig } from 'vite'
|
|
|
|
import { defineConfig, mergeConfig, Plugin, ResolvedConfig } from 'vite'
|
|
|
|
import { SiteConfig, resolveSiteData } from './config'
|
|
|
|
import { SiteConfig } from './config'
|
|
|
|
import { createMarkdownToVueRenderFn } from './markdownToVue'
|
|
|
|
import { createMarkdownToVueRenderFn, clearCache } from './markdownToVue'
|
|
|
|
import { DIST_CLIENT_PATH, APP_PATH, SITE_DATA_REQUEST_PATH } from './alias'
|
|
|
|
import { DIST_CLIENT_PATH, APP_PATH, SITE_DATA_REQUEST_PATH } from './alias'
|
|
|
|
import { slash } from './utils/slash'
|
|
|
|
import { slash } from './utils/slash'
|
|
|
|
import { OutputAsset, OutputChunk } from 'rollup'
|
|
|
|
import { OutputAsset, OutputChunk } from 'rollup'
|
|
|
@ -30,11 +31,11 @@ const isPageChunk = (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
export async function createVitePressPlugin(
|
|
|
|
export async function createVitePressPlugin(
|
|
|
|
root: string,
|
|
|
|
|
|
|
|
siteConfig: SiteConfig,
|
|
|
|
siteConfig: SiteConfig,
|
|
|
|
ssr = false,
|
|
|
|
ssr = false,
|
|
|
|
pageToHashMap?: Record<string, string>,
|
|
|
|
pageToHashMap?: Record<string, string>,
|
|
|
|
clientJSMap?: Record<string, string>
|
|
|
|
clientJSMap?: Record<string, string>,
|
|
|
|
|
|
|
|
recreateServer?: () => Promise<void>
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
const {
|
|
|
|
const {
|
|
|
|
srcDir,
|
|
|
|
srcDir,
|
|
|
@ -244,17 +245,23 @@ export async function createVitePressPlugin(
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
async handleHotUpdate(ctx) {
|
|
|
|
async handleHotUpdate(ctx) {
|
|
|
|
// handle config hmr
|
|
|
|
|
|
|
|
const { file, read, server } = ctx
|
|
|
|
const { file, read, server } = ctx
|
|
|
|
if (file === configPath || configDeps.includes(file)) {
|
|
|
|
if (file === configPath || configDeps.includes(file)) {
|
|
|
|
const newData = await resolveSiteData(root)
|
|
|
|
console.log(
|
|
|
|
if (newData.base !== siteData.base) {
|
|
|
|
c.green(
|
|
|
|
console.warn(
|
|
|
|
`\n${path.relative(
|
|
|
|
`[vitepress]: config.base has changed. Please restart the dev server.`
|
|
|
|
process.cwd(),
|
|
|
|
|
|
|
|
file
|
|
|
|
|
|
|
|
)} changed, restarting server...`
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
clearCache()
|
|
|
|
|
|
|
|
await recreateServer!()
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
console.error(c.red(`failed to restart server. error:\n`), err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
siteData = newData
|
|
|
|
return
|
|
|
|
return [server.moduleGraph.getModuleById(SITE_DATA_REQUEST_PATH)!]
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// hot reload .md files as .vue files
|
|
|
|
// hot reload .md files as .vue files
|
|
|
|