Skip to content
Merged
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/cloudflare-skip-sync-runtime.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/cloudflare": patch
---

Speeds up `astro sync` by no longer starting the Cloudflare runtime during type generation
26 changes: 21 additions & 5 deletions packages/integrations/cloudflare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export default function createIntegration({
const needsImagesBindingForDev = isCompile && command === 'dev';
const usesContentCollections = hasContentCollectionsConfig(config.srcDir);
const prebundleContentRuntime = command === 'dev' && usesContentCollections;
const isTypeGenPhase = command === 'build' || command === 'sync';

const adapterPluginConfig: Partial<PluginConfig> = {
config: cloudflareConfigCustomizer({
Expand Down Expand Up @@ -245,6 +246,21 @@ export default function createIntegration({
// include, and esbuildOptions (e.g. loader) entries are respected.
const userOptimizeDeps = config.vite?.optimizeDeps;

const cloudflareVitePlugins = cfVitePlugin({
...cfPluginConfig,
viteEnvironment: { name: 'ssr' },
assetsOnly: () => _buildOutput === 'static',
});
// `sync` and `build` both run type generation (build via its internal sync
// pass), which creates a temporary Vite server and fires `configureServer`
// the hook that boots the Cloudflare/workerd runtime. Drop it in both so
// type generation doesn't pay that startup cost. See #16332.
if (isTypeGenPhase) {
for (const plugin of cloudflareVitePlugins) {
plugin.configureServer = undefined;
}
}

updateConfig({
build: {
redirects: false,
Expand All @@ -255,11 +271,7 @@ export default function createIntegration({
...(prerenderEnvironment === 'node' && command === 'dev'
? [createNodePrerenderPlugin()]
: []),
cfVitePlugin({
...cfPluginConfig,
viteEnvironment: { name: 'ssr' },
assetsOnly: () => _buildOutput === 'static',
}),
cloudflareVitePlugins,
{
name: '@astrojs/cloudflare:cf-imports',
enforce: 'pre',
Expand All @@ -275,6 +287,10 @@ export default function createIntegration({
{
name: '@astrojs/cloudflare:environment',
configEnvironment(environmentName, _options) {
// Skip dependency pre-bundling during type generation (see `isTypeGenPhase` above).
if (isTypeGenPhase) {
return { optimizeDeps: { noDiscovery: true, include: [] } };
}
const isServerEnvironment = ['astro', 'ssr', 'prerender'].includes(
environmentName,
);
Expand Down
Loading