diff --git a/.changeset/cold-mirrors-joke.md b/.changeset/cold-mirrors-joke.md new file mode 100644 index 000000000000..efdee39399e5 --- /dev/null +++ b/.changeset/cold-mirrors-joke.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Run astro sync in build mode diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index 7d83e731ccda..385b8a9f0804 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -30,7 +30,7 @@ interface CreateViteOptions { settings: AstroSettings; logging: LogOptions; mode: 'dev' | 'build' | string; - // will be undefined when using `sync` + // will be undefined when using `getViteConfig` command?: 'dev' | 'build'; fs?: typeof nodeFs; } @@ -180,32 +180,28 @@ export async function createVite( // We also need to filter out the plugins that are not meant to be applied to the current command: // - If the command is `build`, we filter out the plugins that are meant to be applied for `serve`. // - If the command is `dev`, we filter out the plugins that are meant to be applied for `build`. - if (command) { - let plugins = settings.config.vite?.plugins; - if (plugins) { - const { plugins: _, ...rest } = settings.config.vite; - const applyToFilter = command === 'build' ? 'serve' : 'build'; - const applyArgs = [ - { ...settings.config.vite, mode }, - { command, mode }, - ]; - // @ts-expect-error ignore TS2589: Type instantiation is excessively deep and possibly infinite. - plugins = plugins.flat(Infinity).filter((p) => { - if (!p || p?.apply === applyToFilter) { - return false; - } - - if (typeof p.apply === 'function') { - return p.apply(applyArgs[0], applyArgs[1]); - } + if (command && settings.config.vite?.plugins) { + let { plugins, ...rest } = settings.config.vite; + const applyToFilter = command === 'build' ? 'serve' : 'build'; + const applyArgs = [ + { ...settings.config.vite, mode }, + { command, mode }, + ]; + // @ts-expect-error ignore TS2589: Type instantiation is excessively deep and possibly infinite. + plugins = plugins.flat(Infinity).filter((p) => { + if (!p || p?.apply === applyToFilter) { + return false; + } - return true; - }); + if (typeof p.apply === 'function') { + return p.apply(applyArgs[0], applyArgs[1]); + } - result = vite.mergeConfig(result, { ...rest, plugins }); - } else { - result = vite.mergeConfig(result, settings.config.vite || {}); - } + return true; + }); + result = vite.mergeConfig(result, { ...rest, plugins }); + } else { + result = vite.mergeConfig(result, settings.config.vite || {}); } result = vite.mergeConfig(result, commandConfig); if (result.plugins) { diff --git a/packages/astro/src/core/sync/index.ts b/packages/astro/src/core/sync/index.ts index ae27cdb0feca..be8f84d2a77b 100644 --- a/packages/astro/src/core/sync/index.ts +++ b/packages/astro/src/core/sync/index.ts @@ -39,7 +39,7 @@ export async function sync( optimizeDeps: { entries: [] }, logLevel: 'silent', }, - { settings, logging, mode: 'build', fs } + { settings, logging, mode: 'build', command: 'build', fs } ) );