diff --git a/.changeset/flat-dolphins-admire.md b/.changeset/flat-dolphins-admire.md new file mode 100644 index 000000000000..787a108b73e0 --- /dev/null +++ b/.changeset/flat-dolphins-admire.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Respect `vite.build.emptyOutDir` setting during `astro build` diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index aef8a1aabab7..1a6d3e367924 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -61,7 +61,9 @@ export async function staticBuild(opts: StaticBuildOptions) { // Empty out the dist folder, if needed. Vite has a config for doing this // but because we are running 2 vite builds in parallel, that would cause a race // condition, so we are doing it ourselves - emptyDir(settings.config.outDir, new Set('.git')); + if (settings.config?.vite?.build?.emptyOutDir !== false) { + emptyDir(settings.config.outDir, new Set('.git')); + } // Register plugins const container = createPluginContainer(opts, internals);