diff --git a/.changeset/pretty-pumpkins-work.md b/.changeset/pretty-pumpkins-work.md new file mode 100644 index 0000000000..40d19f5cd6 --- /dev/null +++ b/.changeset/pretty-pumpkins-work.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes an issue that was breaking asset and stylesheet URLs when building for a subpath diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 2884174f46..6150dd9954 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -162,7 +162,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp root: viteConfig.root, envPrefix: 'PUBLIC_', server: viteConfig.server, - base: astroConfig.site ? new URL(astroConfig.site).pathname : '/', + base: astroConfig.base, ssr: viteConfig.ssr, resolve: viteConfig.resolve, } as ViteConfigWithSSR; diff --git a/packages/astro/src/core/config.ts b/packages/astro/src/core/config.ts index 74942e56ff..8b16ce5a0a 100644 --- a/packages/astro/src/core/config.ts +++ b/packages/astro/src/core/config.ts @@ -14,7 +14,7 @@ import load, { resolve, ProloadError } from '@proload/core'; import loadTypeScript from '@proload/plugin-tsm'; import postcssrc from 'postcss-load-config'; import { arraify, isObject } from './util.js'; -import { appendForwardSlash, trimSlashes } from './path.js'; +import { appendForwardSlash, prependForwardSlash, trimSlashes } from './path.js'; load.use([loadTypeScript]); @@ -95,7 +95,7 @@ export const AstroConfigSchema = z.object({ .string() .optional() .default('/') - .transform((val) => appendForwardSlash(trimSlashes(val))), + .transform((val) => prependForwardSlash(appendForwardSlash(trimSlashes(val)))), trailingSlash: z .union([z.literal('always'), z.literal('never'), z.literal('ignore')]) .optional() diff --git a/packages/astro/test/static-build.test.js b/packages/astro/test/static-build.test.js index a461209a20..ce470b2b6c 100644 --- a/packages/astro/test/static-build.test.js +++ b/packages/astro/test/static-build.test.js @@ -96,6 +96,9 @@ describe('Static build', () => { for (const link of links) { const href = $(link).attr('href'); + // The imported .scss file should include the base subpath in the href + expect(href.startsWith('/subpath/')).to.be.true; + /** * The link should be built with the config's `base` included * as a subpath.