From 3117cda0d71b36d2d5234b02c13c1b9da4145997 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Fri, 3 Jun 2022 20:54:29 +0800 Subject: [PATCH] feat: support esm ssr build --- .gitignore | 1 + src/node/build/bundle.ts | 5 ++++- src/node/build/render.ts | 9 ++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index d73d7b2d..802a3627 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ .idea .vite_opt_cache .vscode +.temp dist node_modules pnpm-global diff --git a/src/node/build/bundle.ts b/src/node/build/bundle.ts index ac849112..ae98f54d 100644 --- a/src/node/build/bundle.ts +++ b/src/node/build/bundle.ts @@ -54,7 +54,10 @@ export async function bundle( ), // @ts-ignore ssr: { - noExternal: ['vitepress'] + noExternal: [ + 'vitepress', + '@docsearch/css' + ] }, build: { ...options, diff --git a/src/node/build/render.ts b/src/node/build/render.ts index aa5f217e..99b28c7c 100644 --- a/src/node/build/render.ts +++ b/src/node/build/render.ts @@ -20,9 +20,12 @@ export async function renderPage( pageToHashMap: Record, hashMapString: string ) { - const { createApp } = await import( - pathToFileURL(path.join(config.tempDir, `app.js`)).toString() - ) + const entryPath = [ + 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 routePath = `/${page.replace(/\.md$/, '')}` const siteData = resolveSiteDataByRoute(config.site, routePath)