feat: support esm ssr build

pull/707/head
Anthony Fu 3 years ago
parent 0927a7393b
commit 3117cda0d7

1
.gitignore vendored

@ -6,6 +6,7 @@
.idea .idea
.vite_opt_cache .vite_opt_cache
.vscode .vscode
.temp
dist dist
node_modules node_modules
pnpm-global pnpm-global

@ -54,7 +54,10 @@ export async function bundle(
), ),
// @ts-ignore // @ts-ignore
ssr: { ssr: {
noExternal: ['vitepress'] noExternal: [
'vitepress',
'@docsearch/css'
]
}, },
build: { build: {
...options, ...options,

@ -20,9 +20,12 @@ export async function renderPage(
pageToHashMap: Record<string, string>, pageToHashMap: Record<string, string>,
hashMapString: string hashMapString: string
) { ) {
const { createApp } = await import( const entryPath = [
pathToFileURL(path.join(config.tempDir, `app.js`)).toString() path.join(config.tempDir, `app.mjs`),
) path.join(config.tempDir, `app.js`)
].find((i) => fs.existsSync(i))!
const { createApp } = await import(pathToFileURL(entryPath).toString())
const { app, router } = createApp() const { app, router } = createApp()
const routePath = `/${page.replace(/\.md$/, '')}` const routePath = `/${page.replace(/\.md$/, '')}`
const siteData = resolveSiteDataByRoute(config.site, routePath) const siteData = resolveSiteDataByRoute(config.site, routePath)

Loading…
Cancel
Save