diff --git a/.changeset/rare-parents-repeat.md b/.changeset/rare-parents-repeat.md new file mode 100644 index 000000000000..3c4de016bd3c --- /dev/null +++ b/.changeset/rare-parents-repeat.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Experimental build option to try two build runs for the cloudflare adapter diff --git a/packages/astro/src/core/build/index.ts b/packages/astro/src/core/build/index.ts index 50085d58132a..43642e730008 100644 --- a/packages/astro/src/core/build/index.ts +++ b/packages/astro/src/core/build/index.ts @@ -50,6 +50,14 @@ export interface BuildOptions { * @default false */ force?: boolean; + + /** + * Build a SSR project without running the static build. This allows us to use a workaround to split up the build into two builds, one with the old behavior and one without the prerendering logic. This is currently used for testng in the Cloudlfare adapter. + * + * @internal very specific to the Cloudflare adapter + * @default false + */ + ssronly?: boolean; } /** @@ -99,6 +107,7 @@ class AstroBuilder { private manifest: ManifestData; private timer: Record; private teardownCompiler: boolean; + private ssronly: boolean; constructor(settings: AstroSettings, options: AstroBuilderOptions) { if (options.mode) { @@ -112,6 +121,7 @@ class AstroBuilder { : `http://localhost:${settings.config.server.port}`; this.manifest = { routes: [] }; this.timer = {}; + this.ssronly = options.ssronly ?? false; } /** Setup Vite and run any async setup logic that couldn't run inside of the constructor. */ @@ -196,7 +206,9 @@ class AstroBuilder { }; const { internals, ssrOutputChunkNames, contentFileNames } = await viteBuild(opts); - await staticBuild(opts, internals, ssrOutputChunkNames, contentFileNames); + if (!this.ssronly) { + await staticBuild(opts, internals, ssrOutputChunkNames, contentFileNames); + } // Write any additionally generated assets to disk. this.timer.assetsStart = performance.now(); diff --git a/packages/astro/src/core/index.ts b/packages/astro/src/core/index.ts index 31d868311455..1e1d19d533e6 100644 --- a/packages/astro/src/core/index.ts +++ b/packages/astro/src/core/index.ts @@ -14,7 +14,7 @@ export { default as preview } from './preview/index.js'; * @experimental The JavaScript API is experimental */ // Wrap `_build` to prevent exposing the second internal options parameter -export const build = (inlineConfig: AstroInlineConfig) => _build(inlineConfig); +export const build = (inlineConfig: AstroInlineConfig, options: { ssronly?: boolean }) => _build(inlineConfig, options); /** * Generates TypeScript types for all Astro modules. This sets up a `src/env.d.ts` file for type inferencing,