Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Add build option to build only ssr #11155

Closed
wants to merge 3 commits into from
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/rare-parents-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Experimental build option to try two build runs for the cloudflare adapter
14 changes: 13 additions & 1 deletion packages/astro/src/core/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
alexanderniebuhr marked this conversation as resolved.
Show resolved Hide resolved
* @default false
*/
ssronly?: boolean;
}

/**
Expand Down Expand Up @@ -99,6 +107,7 @@ class AstroBuilder {
private manifest: ManifestData;
private timer: Record<string, number>;
private teardownCompiler: boolean;
private ssronly: boolean;

constructor(settings: AstroSettings, options: AstroBuilderOptions) {
if (options.mode) {
Expand All @@ -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. */
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading