diff --git a/.changeset/quick-items-switch.md b/.changeset/quick-items-switch.md new file mode 100644 index 000000000..47a39e29e --- /dev/null +++ b/.changeset/quick-items-switch.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix regression that caused some stateful Vite plugins to assume they were running in `dev` mode during the `build`. diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index c25668af4..f29bdc0ae 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -31,6 +31,7 @@ interface CreateViteOptions { logging: LogOptions; mode: 'dev' | 'build' | string; fs?: typeof nodeFs; + allowUserPlugins?: boolean; } const ALWAYS_NOEXTERNAL = [ @@ -48,7 +49,7 @@ const ALWAYS_NOEXTERNAL = [ /** Return a common starting point for all Vite actions */ export async function createVite( commandConfig: vite.InlineConfig, - { settings, logging, mode, fs = nodeFs }: CreateViteOptions + { settings, logging, mode, fs = nodeFs, allowUserPlugins = true }: CreateViteOptions ): Promise { const astroPkgsConfig = await crawlFrameworkPkgs({ root: fileURLToPath(settings.config.root), @@ -170,7 +171,9 @@ export async function createVite( // 3. integration-provided vite config, via the `config:setup` hook // 4. command vite config, passed as the argument to this function let result = commonConfig; - result = vite.mergeConfig(result, settings.config.vite || {}); + if (allowUserPlugins) { + result = vite.mergeConfig(result, settings.config.vite || {}); + } result = vite.mergeConfig(result, commandConfig); if (result.plugins) { sortPlugins(result.plugins); diff --git a/packages/astro/src/core/sync/index.ts b/packages/astro/src/core/sync/index.ts index ae27cdb0f..f1c8f709e 100644 --- a/packages/astro/src/core/sync/index.ts +++ b/packages/astro/src/core/sync/index.ts @@ -39,7 +39,8 @@ export async function sync( optimizeDeps: { entries: [] }, logLevel: 'silent', }, - { settings, logging, mode: 'build', fs } + // Important to disallow user-provided Vite plugins that might be stateful! + { settings, logging, mode: 'build', fs, allowUserPlugins: false } ) );