From 326aced56a1d9d2c0f4c5d600e9a0cc751b39f8c Mon Sep 17 00:00:00 2001 From: Tony Sullivan Date: Wed, 20 Apr 2022 15:41:16 +0200 Subject: [PATCH] fix: handling config that provides a base but no site --- packages/astro/src/core/build/generate.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index e91bd50898..c85d758abe 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -176,9 +176,11 @@ async function generatePath( debug('build', `Generating: ${pathname}`); - const site = !astroConfig.base || astroConfig.base === './' - ? astroConfig.site - : joinPaths(astroConfig.site, astroConfig.base); + // If a base path was provided, append it to the site URL. This ensures that + // all injected scripts and links are referenced relative to the site and subpath. + const site = astroConfig.base && astroConfig.base !== './' + ? joinPaths(astroConfig.site || 'http://localhost/', astroConfig.base) + : astroConfig.site; const links = createLinkStylesheetElementSet(linkIds.reverse(), site); const scripts = createModuleScriptElementWithSrcSet(hoistedId ? [hoistedId] : [], site);