From 2f8ef43da54888192fe1aad67033e7af9b606758 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 15 May 2020 21:16:18 -0400 Subject: [PATCH] handle base option --- lib/app/index.js | 2 +- src/build/bundle.ts | 1 + src/config.ts | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/app/index.js b/lib/app/index.js index 241dc644f193..7ff96f5e2620 100644 --- a/lib/app/index.js +++ b/lib/app/index.js @@ -60,7 +60,7 @@ export function createApp() { const useLeanBuild = isInitialPageLoad || initialPath === pagePath pagePath = (inBrowser ? __BASE__ + '_assets/' : './') + - pagePath.slice(1).replace(/\//g, '_') + + pagePath.slice(inBrowser ? __BASE__.length : 1).replace(/\//g, '_') + (useLeanBuild ? '.md.lean.js' : '.md.js') } diff --git a/src/build/bundle.ts b/src/build/bundle.ts index 75586008ed68..6f82f444af31 100644 --- a/src/build/bundle.ts +++ b/src/build/bundle.ts @@ -85,6 +85,7 @@ export async function bundle( const { rollupInputOptions = {}, rollupOutputOptions = {} } = options const viteOptions: ViteBuildOptions = { ...options, + base: config.site.base, resolvers: [resolver], outDir: config.outDir, assetsDir: ASSETS_DIR, diff --git a/src/config.ts b/src/config.ts index 1c463c5628ba..e7eb06808135 100644 --- a/src/config.ts +++ b/src/config.ts @@ -91,7 +91,7 @@ export async function resolveSiteData(root: string): Promise { return { title: userConfig.title || 'VitePress', description: userConfig.description || 'A VitePress site', - base: userConfig.base || '/', + base: userConfig.base ? userConfig.base.replace(/([^/])$/, '$1/') : '/', head: userConfig.head || [], themeConfig: userConfig.themeConfig || {} }