pull/4525/head
Divyansh Singh 7 months ago
parent 25dcad1389
commit 9da44f6c8c

@ -95,7 +95,7 @@ export async function createVitePressPlugin(
// lazy require plugin-vue to respect NODE_ENV in @vue/compiler-x // lazy require plugin-vue to respect NODE_ENV in @vue/compiler-x
const vuePlugin = await import('@vitejs/plugin-vue').then((r) => const vuePlugin = await import('@vitejs/plugin-vue').then((r) =>
r.default({ r.default({
include: [/\.vue$/, /\.md$/], include: /\.(?:vue|md)$/,
...userVuePluginOptions, ...userVuePluginOptions,
template: { template: {
...userVuePluginOptions?.template, ...userVuePluginOptions?.template,
@ -195,9 +195,7 @@ export async function createVitePressPlugin(
} }
} }
data = serializeFunctions(data) data = serializeFunctions(data)
return `${deserializeFunctions};export default deserializeFunctions(JSON.parse(${JSON.stringify( return `${deserializeFunctions};export default deserializeFunctions(JSON.parse(${JSON.stringify(JSON.stringify(data))}))`
JSON.stringify(data)
)}))`
} }
}, },
@ -205,6 +203,7 @@ export async function createVitePressPlugin(
if (id.endsWith('.vue')) { if (id.endsWith('.vue')) {
return processClientJS(code, id) return processClientJS(code, id)
} else if (id.endsWith('.md')) { } else if (id.endsWith('.md')) {
console.log('transform', id)
// transform .md files into vueSrc so plugin-vue can handle it // transform .md files into vueSrc so plugin-vue can handle it
const { vueSrc, deadLinks, includes } = await markdownToVue( const { vueSrc, deadLinks, includes } = await markdownToVue(
code, code,
@ -254,9 +253,7 @@ export async function createVitePressPlugin(
if (themeRE.test(file)) { if (themeRE.test(file)) {
siteConfig.logger.info( siteConfig.logger.info(
c.green( c.green(
`${path.relative(process.cwd(), _file)} ${ `${path.relative(process.cwd(), _file)} ${added ? 'created' : 'deleted'}, restarting server...\n`
added ? 'created' : 'deleted'
}, restarting server...\n`
), ),
{ clear: true, timestamp: true } { clear: true, timestamp: true }
) )
@ -366,8 +363,10 @@ export async function createVitePressPlugin(
} }
}, },
async handleHotUpdate(ctx) { async hotUpdate(ctx) {
const { file, read, server } = ctx if (this.environment.name !== 'client') return
const { file, read } = ctx
if (file === configPath || configDeps.includes(file)) { if (file === configPath || configDeps.includes(file)) {
siteConfig.logger.info( siteConfig.logger.info(
c.green( c.green(
@ -392,6 +391,7 @@ export async function createVitePressPlugin(
// hot reload .md files as .vue files // hot reload .md files as .vue files
if (file.endsWith('.md')) { if (file.endsWith('.md')) {
const content = await read() const content = await read()
console.log('hotUpdate', file)
const { pageData, vueSrc } = await markdownToVue( const { pageData, vueSrc } = await markdownToVue(
content, content,
file, file,
@ -405,7 +405,7 @@ export async function createVitePressPlugin(
} }
// notify the client to update page data // notify the client to update page data
server.ws.send({ this.environment.hot.send({
type: 'custom', type: 'custom',
event: 'vitepress:pageData', event: 'vitepress:pageData',
data: payload data: payload

Loading…
Cancel
Save