File tree 3 files changed +12
-5
lines changed
3 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import { renderPage } from './render'
6
6
import { OutputChunk , OutputAsset } from 'rollup'
7
7
8
8
export type BuildOptions = Pick <
9
- ViteBuildOptions ,
9
+ Partial < ViteBuildOptions > ,
10
10
| 'root'
11
11
| 'rollupInputOptions'
12
12
| 'rollupOutputOptions'
Original file line number Diff line number Diff line change @@ -118,7 +118,7 @@ export async function bundle(
118
118
119
119
// resolve options to pass to vite
120
120
const { rollupInputOptions = { } , rollupOutputOptions = { } } = options
121
- const viteOptions : ViteBuildOptions = {
121
+ const viteOptions : Partial < ViteBuildOptions > = {
122
122
...options ,
123
123
base : config . site . base ,
124
124
resolvers : [ resolver ] ,
@@ -153,5 +153,5 @@ export async function bundle(
153
153
outDir : config . tempDir
154
154
} )
155
155
156
- return [ clientResult , serverResult , pageToHashMap ]
156
+ return [ clientResult [ 0 ] , serverResult [ 0 ] , pageToHashMap ]
157
157
}
Original file line number Diff line number Diff line change @@ -63,16 +63,23 @@ export function createMarkdownToVueRenderFn(
63
63
}
64
64
65
65
const scriptRE = / < \/ s c r i p t > /
66
+ const defaultExportRE = / ( (?: ^ | \n | ; ) \s * ) e x p o r t ( \s * ) d e f a u l t /
67
+ const namedDefaultExportRE = / ( (?: ^ | \n | ; ) \s * ) e x p o r t ( .+ ) a s ( \s * ) d e f a u l t /
66
68
67
69
function injectPageData ( tags : string [ ] , data : PageData ) {
68
70
const code = `\nexport const __pageData = ${ JSON . stringify (
69
71
JSON . stringify ( data )
70
72
) } `
71
73
const existingScriptIndex = tags . findIndex ( ( tag ) => scriptRE . test ( tag ) )
72
74
if ( existingScriptIndex > - 1 ) {
73
- tags [ existingScriptIndex ] = tags [ existingScriptIndex ] . replace (
75
+ const tagSrc = tags [ existingScriptIndex ]
76
+ // user has <script> tag inside markdown
77
+ // if it doesn't have export default it will error out on build
78
+ const hasDefaultExport =
79
+ defaultExportRE . test ( tagSrc ) || namedDefaultExportRE . test ( tagSrc )
80
+ tags [ existingScriptIndex ] = tagSrc . replace (
74
81
scriptRE ,
75
- code + `</script>`
82
+ code + ( hasDefaultExport ? `` : `\nexport default{}\n` ) + `</script>`
76
83
)
77
84
} else {
78
85
tags . push ( `<script>${ code } \nexport default {}</script>` )
You can’t perform that action at this time.
0 commit comments