Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fast-sync-temp-server.md
Original file line number Diff line number Diff line change
@@ -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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

32 changes: 32 additions & 0 deletions packages/astro/src/core/sync/index.ts

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the correct fix. For example, in your comment you say that some Astro plugins rely on this hook, but what if there are other plugins (integrations, user, etc.) that need this hook? I believe this fix should live in the Cloudflare adapter.

Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,45 @@ 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(
{
server: { middlewareMode: true, hmr: false, watch: null, ws: false },
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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use delete, but assign undefined. 90% of the time, delete is usually incorrect.

}
}
},
},
],
},
{
routesList,
Expand Down
Loading