Skip to content

Commit a5ffe45

Browse files
committed
Rename mode to output
1 parent 7125952 commit a5ffe45

53 files changed

Lines changed: 101 additions & 83 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/famous-coins-destroy.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This change introduces a new configuration option `mode`. Mode can be either
1818

1919
The default, `static`, can be omitted from your config file.
2020

21-
If you want to use SSR you now need to provide `mode: 'server'` *in addition* to an adapter.
21+
If you want to use SSR you now need to provide `output: 'server'` *in addition* to an adapter.
2222

2323
The `adapter` configuration has been renamed to `deploy`. In the future adapters will support configuring a static site as well!
2424

@@ -31,6 +31,6 @@ import netlify from '@astrojs/netlify/functions';
3131
export default defineConfig({
3232
- adapter: netlify(),
3333
+ deploy: netlify(),
34-
+ mode: 'server',
34+
+ output: 'server',
3535
});
3636
```

examples/ssr/astro.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import node from '@astrojs/node';
44

55
// https://astro.build/config
66
export default defineConfig({
7-
mode: 'server',
7+
output: 'server',
88
deploy: node(),
99
integrations: [svelte()],
1010
});

packages/astro/src/@types/astro.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,26 @@ export interface AstroUserConfig {
638638
*/
639639
deploy?: AstroIntegration;
640640

641-
// TODO: Document
642-
mode?: 'static' | 'server';
641+
/**
642+
* @docs
643+
* @kind heading
644+
* @name Output
645+
* @description
646+
*
647+
* Specifies the output target for builds.
648+
*
649+
* - 'static' - Building a static site to be deploy to any static host.
650+
* - 'server' - Building an app to be deployed to a host supporting SSR (server-side rendering).
651+
*
652+
* ```js
653+
* import { defineConfig } from 'astro/config';
654+
*
655+
* export default defineConfig({
656+
* output: 'static'
657+
* })
658+
* ```
659+
*/
660+
output?: 'static' | 'server';
643661

644662

645663
/**

packages/astro/src/core/build/generate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export async function generatePages(
9797
const timer = performance.now();
9898
info(opts.logging, null, `\n${bgGreen(black(' generating static routes '))}`);
9999

100-
const ssr = opts.astroConfig.mode === 'server';
100+
const ssr = opts.astroConfig.output === 'server';
101101
const serverEntry = opts.buildConfig.serverEntry;
102102
const outFolder = ssr ? opts.buildConfig.server : opts.astroConfig.outDir;
103103
const ssrEntryURL = new URL('./' + serverEntry + `?time=${Date.now()}`, outFolder);
@@ -207,7 +207,7 @@ async function generatePath(
207207
}
208208
}
209209

210-
const ssr = opts.astroConfig.mode === 'server';
210+
const ssr = opts.astroConfig.output === 'server';
211211
const url = new URL(opts.astroConfig.base + removeLeadingForwardSlash(pathname), origin);
212212
const options: RenderOptions = {
213213
adapterName: undefined,

packages/astro/src/core/build/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class AstroBuilder {
102102
await runHookBuildStart({ config: this.config, buildConfig });
103103

104104
const getPrettyDeployTarget = (adapter: AstroAdapter | undefined) => adapter?.name || 'unknown';
105-
info(this.logging, 'build', `build target: ${colors.green(this.config.mode)}`);
105+
info(this.logging, 'build', `build target: ${colors.green(this.config.output)}`);
106106
info(this.logging, 'build', `deploy target: ${colors.green(getPrettyDeployTarget(this.config._ctx.adapter))}`);
107107
info(this.logging, 'build', 'Collecting build info...');
108108
this.timer.loadStart = performance.now();
@@ -113,7 +113,7 @@ class AstroBuilder {
113113
origin,
114114
routeCache: this.routeCache,
115115
viteServer,
116-
ssr: this.config.mode === 'server',
116+
ssr: this.config.output === 'server',
117117
});
118118

119119
debug('build', timerMessage('All pages loaded', this.timer.loadStart));
@@ -174,7 +174,7 @@ class AstroBuilder {
174174
logging: this.logging,
175175
timeStart: this.timer.init,
176176
pageCount: pageNames.length,
177-
buildMode: this.config.mode,
177+
buildMode: this.config.output,
178178
});
179179
}
180180
}

packages/astro/src/core/build/page-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export async function collectPagesData(
6868
};
6969

7070
clearInterval(routeCollectionLogTimeout);
71-
if (astroConfig.mode === 'static') {
71+
if (astroConfig.output === 'static') {
7272
const html = `${route.pathname}`.replace(/\/?$/, '/index.html');
7373
debug(
7474
'build',

packages/astro/src/core/build/static-build.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ export async function staticBuild(opts: StaticBuildOptions) {
2626

2727
// Verify this app is buildable.
2828
if(isModeServerWithNoAdapter(opts.astroConfig)) {
29-
throw new Error(`Cannot use mode: 'server' without an adapter. Please install and configure an adapter by setting it on the deploy configuration.
29+
throw new Error(`Cannot use output: 'server' without an adapter. Please install and configure an adapter by setting it on the deploy configuration.
3030
3131
export default {
32-
mode: 'static',
32+
output: 'static',
3333
adapter: netlify(),
3434
}`)
3535
}
@@ -69,7 +69,7 @@ export default {
6969
info(
7070
opts.logging,
7171
'build',
72-
`Building ${astroConfig.mode} entrypoints...`
72+
`Building ${astroConfig.output} entrypoints...`
7373
);
7474
const ssrResult = (await ssrBuild(opts, internals, pageInput)) as RollupOutput;
7575
info(opts.logging, 'build', dim(`Completed in ${getTimeStat(timer.ssr, performance.now())}.`));
@@ -90,7 +90,7 @@ export default {
9090
await clientBuild(opts, internals, clientInput);
9191

9292
timer.generate = performance.now();
93-
if (astroConfig.mode === 'static') {
93+
if (astroConfig.output === 'static') {
9494
try {
9595
await generatePages(ssrResult, opts, internals, facadeIdToPageDataMap);
9696
} finally {
@@ -107,7 +107,7 @@ export default {
107107

108108
async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, input: Set<string>) {
109109
const { astroConfig, viteConfig } = opts;
110-
const ssr = astroConfig.mode === 'server';
110+
const ssr = astroConfig.output === 'server';
111111
const out = ssr ? opts.buildConfig.server : astroConfig.outDir;
112112

113113
const viteBuildConfig: ViteConfigWithSSR = {
@@ -151,7 +151,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
151151
}),
152152
...(viteConfig.plugins || []),
153153
// SSR needs to be last
154-
opts.astroConfig.mode === 'server' && vitePluginSSR(internals, opts.astroConfig._ctx.adapter!),
154+
opts.astroConfig.output === 'server' && vitePluginSSR(internals, opts.astroConfig._ctx.adapter!),
155155
vitePluginAnalyzer(opts.astroConfig, internals),
156156
],
157157
publicDir: ssr ? false : viteConfig.publicDir,
@@ -181,7 +181,7 @@ async function clientBuild(
181181
) {
182182
const { astroConfig, viteConfig } = opts;
183183
const timer = performance.now();
184-
const ssr = astroConfig.mode === 'server';
184+
const ssr = astroConfig.output === 'server';
185185
const out = ssr ? opts.buildConfig.client : astroConfig.outDir;
186186

187187
// Nothing to do if there is no client-side JS.
@@ -282,7 +282,7 @@ async function copyFiles(fromFolder: URL, toFolder: URL) {
282282

283283
async function ssrMoveAssets(opts: StaticBuildOptions) {
284284
info(opts.logging, 'build', 'Rearranging server assets...');
285-
const serverRoot = opts.astroConfig.mode === 'static'
285+
const serverRoot = opts.astroConfig.output === 'static'
286286
? opts.buildConfig.client
287287
: opts.buildConfig.server;
288288
const clientRoot = opts.buildConfig.client;

packages/astro/src/core/build/vite-plugin-pages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function vitePluginPages(opts: StaticBuildOptions, internals: BuildIntern
1010
name: '@astro/plugin-build-pages',
1111

1212
options(options) {
13-
if (opts.astroConfig.mode === 'static') {
13+
if (opts.astroConfig.output === 'static') {
1414
return addRollupInput(options, [pagesVirtualModuleId]);
1515
}
1616
},

packages/astro/src/core/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export const AstroConfigSchema = z.object({
124124
.union([z.literal('always'), z.literal('never'), z.literal('ignore')])
125125
.optional()
126126
.default(ASTRO_CONFIG_DEFAULTS.trailingSlash),
127-
mode: z
127+
output: z
128128
.union([z.literal('static'), z.literal('server')])
129129
.optional()
130130
.default('static'),

packages/astro/src/core/endpoint/dev/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ export async function call(ssrOpts: SSROptions) {
77
const [, mod] = await preload(ssrOpts);
88
return await callEndpoint(mod as unknown as EndpointHandler, {
99
...ssrOpts,
10-
ssr: ssrOpts.astroConfig.mode === 'server',
10+
ssr: ssrOpts.astroConfig.output === 'server',
1111
});
1212
}

0 commit comments

Comments
 (0)