mirror of
https://github.com/withastro/astro.git
synced 2025-03-10 23:01:26 -05:00
feat: hybrid output (#6991)
* update config schema * adapt default route `prerender` value * adapt error message for hybrid output * core hybrid output support * add JSDocs for hybrid output * dev server hybrid output support * defer hybrid output check * update endpoint request warning * support `output=hybrid` in integrations * put constant variable out of for loop * revert: reapply back ssr plugin in ssr mode * change `prerender` option default * apply `prerender` by default in hybrid mode * simplfy conditional * update config schema * add `isHybridOutput` helper * more readable prerender condition * set default prerender value if no export is found * only add `pagesVirtualModuleId` ro rollup input in `output=static` * don't export vite plugin * remove unneeded check * don't prerender when it shouldn't * extract fallback `prerender` meta Extract the fallback `prerender` module meta out of the `scan` function. It shouldn't be its responsibility to handle that * pass missing argument to function * test: update cloudflare integration tests * test: update tests of vercel integration * test: update tests of node integration * test: update tests of netlify func integration * test: update tests of netlify edge integration * throw when `hybrid` mode is malconfigured * update node integraiton `output` warning * test(WIP): skip node prerendering tests for now * remove non-existant import * test: bring back prerendering tests * remove outdated comments * test: refactor test to support windows paths * remove outdated comments * apply sarah review Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * docs: `experiment.hybridOutput` jsodcs * test: prevent import from being cached * refactor: extract hybrid output check to function * add `hybrid` to output warning in adapter hooks * chore: changeset * add `.js` extension to import * chore: use spaces instead of tabs for gh formating * resolve merge conflict * chore: move test to another file for consitency --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> Co-authored-by: Matthew Phillips <matthew@skypack.dev>
This commit is contained in:
parent
c8d0f22577
commit
a9c888d2e9
6 changed files with 32 additions and 4 deletions
|
@ -80,7 +80,7 @@ export default function vercelEdge({
|
|||
|
||||
if (config.output === 'static') {
|
||||
throw new Error(`
|
||||
[@astrojs/vercel] \`output: "server"\` is required to use the edge adapter.
|
||||
[@astrojs/vercel] \`output: "server"\` or \`output: "hybrid"\` is required to use the edge adapter.
|
||||
|
||||
`);
|
||||
}
|
||||
|
|
5
packages/integrations/vercel/src/lib/prerender.ts
Normal file
5
packages/integrations/vercel/src/lib/prerender.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import type { AstroConfig } from 'astro';
|
||||
|
||||
export function isHybridOutput(config: AstroConfig) {
|
||||
return config.experimental.hybridOutput && config.output === 'hybrid';
|
||||
}
|
|
@ -75,7 +75,7 @@ export default function vercelServerless({
|
|||
|
||||
if (config.output === 'static') {
|
||||
throw new Error(`
|
||||
[@astrojs/vercel] \`output: "server"\` is required to use the serverless adapter.
|
||||
[@astrojs/vercel] \`output: "server"\` or \`output: "hybrid"\` is required to use the serverless adapter.
|
||||
|
||||
`);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import {
|
|||
import { exposeEnv } from '../lib/env.js';
|
||||
import { emptyDir, getVercelOutput, writeJson } from '../lib/fs.js';
|
||||
import { getRedirects } from '../lib/redirects.js';
|
||||
import { isHybridOutput } from '../lib/prerender.js';
|
||||
|
||||
const PACKAGE_NAME = '@astrojs/vercel/static';
|
||||
|
||||
|
@ -54,7 +55,7 @@ export default function vercelStatic({
|
|||
setAdapter(getAdapter());
|
||||
_config = config;
|
||||
|
||||
if (config.output === 'server') {
|
||||
if (config.output === 'server' || isHybridOutput(config)) {
|
||||
throw new Error(`${PACKAGE_NAME} should be used with output: 'static'`);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
export const prerender = true
|
||||
export const prerender = import.meta.env.PRERENDER;
|
||||
---
|
||||
|
||||
<html>
|
||||
|
|
|
@ -6,6 +6,7 @@ describe('Serverless prerender', () => {
|
|||
let fixture;
|
||||
|
||||
before(async () => {
|
||||
process.env.PRERENDER = true;
|
||||
fixture = await loadFixture({
|
||||
root: './fixtures/serverless-prerender/',
|
||||
});
|
||||
|
@ -16,3 +17,24 @@ describe('Serverless prerender', () => {
|
|||
expect(await fixture.readFile('../.vercel/output/static/index.html')).to.be.ok;
|
||||
});
|
||||
});
|
||||
|
||||
describe('Serverless hybrid rendering', () => {
|
||||
/** @type {import('./test-utils').Fixture} */
|
||||
let fixture;
|
||||
|
||||
before(async () => {
|
||||
process.env.PRERENDER = true;
|
||||
fixture = await loadFixture({
|
||||
root: './fixtures/serverless-prerender/',
|
||||
output:'hybrid',
|
||||
experimental:{
|
||||
hybridOutput: true
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('build successful', async () => {
|
||||
await fixture.build();
|
||||
expect(await fixture.readFile('../.vercel/output/static/index.html')).to.be.ok;
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue