diff --git a/src/node/build/build.ts b/src/node/build/build.ts index 8464b2656c5a..f46d556c2def 100644 --- a/src/node/build/build.ts +++ b/src/node/build/build.ts @@ -6,7 +6,7 @@ import { renderPage } from './render' import { OutputChunk, OutputAsset } from 'rollup' export type BuildOptions = Pick< - ViteBuildOptions, + Partial, | 'root' | 'rollupInputOptions' | 'rollupOutputOptions' diff --git a/src/node/build/bundle.ts b/src/node/build/bundle.ts index b3ef8d96c2f7..7cdabfe755d2 100644 --- a/src/node/build/bundle.ts +++ b/src/node/build/bundle.ts @@ -118,7 +118,7 @@ export async function bundle( // resolve options to pass to vite const { rollupInputOptions = {}, rollupOutputOptions = {} } = options - const viteOptions: ViteBuildOptions = { + const viteOptions: Partial = { ...options, base: config.site.base, resolvers: [resolver], @@ -153,5 +153,5 @@ export async function bundle( outDir: config.tempDir }) - return [clientResult, serverResult, pageToHashMap] + return [clientResult[0], serverResult[0], pageToHashMap] } diff --git a/src/node/markdownToVue.ts b/src/node/markdownToVue.ts index f6715b1e349a..34594d60530e 100644 --- a/src/node/markdownToVue.ts +++ b/src/node/markdownToVue.ts @@ -63,6 +63,8 @@ export function createMarkdownToVueRenderFn( } const scriptRE = /<\/script>/ +const defaultExportRE = /((?:^|\n|;)\s*)export(\s*)default/ +const namedDefaultExportRE = /((?:^|\n|;)\s*)export(.+)as(\s*)default/ function injectPageData(tags: string[], data: PageData) { const code = `\nexport const __pageData = ${JSON.stringify( @@ -70,9 +72,14 @@ function injectPageData(tags: string[], data: PageData) { )}` const existingScriptIndex = tags.findIndex((tag) => scriptRE.test(tag)) if (existingScriptIndex > -1) { - tags[existingScriptIndex] = tags[existingScriptIndex].replace( + const tagSrc = tags[existingScriptIndex] + // user has ` + code + (hasDefaultExport ? `` : `\nexport default{}\n`) + `` ) } else { tags.push(``)