diff --git a/.changeset/late-cups-jam.md b/.changeset/late-cups-jam.md new file mode 100644 index 000000000000..2af2b93d9e4e --- /dev/null +++ b/.changeset/late-cups-jam.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +copy assets even if outDir is out of process.cwd() diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 810e17974123..58d3c6c568e4 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -242,11 +242,6 @@ async function clientBuild( async function cleanSsrOutput(opts: StaticBuildOptions) { const out = getOutDirWithinCwd(opts.settings.config.outDir); - // Clean out directly if the outDir is outside of root - if (out.toString() !== opts.settings.config.outDir.toString()) { - await fs.promises.rm(out, { recursive: true }); - return; - } // The SSR output is all .mjs files, the client output is not. const files = await glob('**/*.mjs', { cwd: fileURLToPath(out), @@ -257,6 +252,13 @@ async function cleanSsrOutput(opts: StaticBuildOptions) { await fs.promises.rm(url); }) ); + // Clean out directly if the outDir is outside of root + if (out.toString() !== opts.settings.config.outDir.toString()) { + // Copy assets before cleaning directory if outside root + copyFiles(out, opts.settings.config.outDir); + await fs.promises.rm(out, { recursive: true }); + return; + } } async function copyFiles(fromFolder: URL, toFolder: URL) {