diff --git a/.changeset/fast-sync-temp-server.md b/.changeset/fast-sync-temp-server.md new file mode 100644 index 000000000000..bd170c55b6c7 --- /dev/null +++ b/.changeset/fast-sync-temp-server.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Skips adapter `configureServer` hooks and per-environment dependency pre-bundling during the temporary Vite server used by `astro build` for type generation. The temp server only resolves virtual modules — it never serves HTTP requests — so starting adapter runtimes (e.g. miniflare/workerd via `@astrojs/cloudflare`) and pre-bundling adapter `optimizeDeps.include` lists were both unnecessary. On a representative project this reduces the “Types Generated” phase from ~3.6 s to ~125 ms. diff --git a/packages/astro/src/core/sync/index.ts b/packages/astro/src/core/sync/index.ts index bf04261585f1..bcec400b72d3 100644 --- a/packages/astro/src/core/sync/index.ts +++ b/packages/astro/src/core/sync/index.ts @@ -234,6 +234,12 @@ async function createTempViteServer( { dev: true }, ); + // Disable dependency optimization for all environments. The temp server only needs + // to resolve virtual modules for type generation, not pre-bundle dependencies. + // Setting this per-environment ensures adapter plugins (e.g. Cloudflare) see the + // flag and skip injecting their own optimizeDeps.include lists. + const noOptimize = { optimizeDeps: { noDiscovery: true, include: [] } }; + const tempViteServer = await createServer( await createVite( { @@ -241,6 +247,32 @@ async function createTempViteServer( optimizeDeps: { noDiscovery: true }, ssr: { external: [] }, logLevel: 'silent', + environments: { + client: noOptimize, + ssr: noOptimize, + astro: noOptimize, + prerender: noOptimize, + }, + plugins: [ + // Strip `configureServer` hooks from non-Astro plugins. The temp + // server is only used to resolve modules for type generation — it + // never serves HTTP requests. Removing these hooks prevents adapter + // plugins from starting heavy runtimes (e.g. miniflare/workerd for + // Cloudflare). Astro's own plugins (prefixed with `astro:`) are + // preserved because some rely on configureServer to set up state + // needed by their other hooks. + { + name: 'astro:sync:strip-server-hooks', + enforce: 'pre', + configResolved(config) { + for (const plugin of config.plugins) { + if (plugin.configureServer && !plugin.name.startsWith('astro:')) { + delete plugin.configureServer; + } + } + }, + }, + ], }, { routesList,