-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
feat: hybrid output #6991
feat: hybrid output #6991
Changes from 45 commits
99c3bfa
e4c614d
1b05568
e9408cf
ba0c6cd
06a8f69
6d509b5
2d7263e
96cffb7
70c60c9
3a4541d
2788683
157c4e0
0fa2ded
459b9d3
b3c6e24
21f7a41
f18245c
3496afa
cc4fd2d
b44a926
b756753
0b14c61
aaa9896
ef2ffb1
7ca73e8
8a64125
e941ad7
5e54411
5f7c217
7ba6bcb
e2c582a
5efc41e
f104d5d
fb02e34
109fd60
2b9a37e
0e82f30
fa2f92c
0478cea
ae079eb
79fdfd6
cdb5816
b818f79
d5bf324
a1f1558
bada941
091e9c8
037efbc
e6bd737
e595d21
c408482
3f340a3
eb55a43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,15 +111,17 @@ export async function viteBuild(opts: StaticBuildOptions) { | |
|
||
export async function staticBuild(opts: StaticBuildOptions, internals: BuildInternals) { | ||
const { settings } = opts; | ||
switch (settings.config.output) { | ||
case 'static': { | ||
const isHybridOutput = | ||
settings.config.experimental.hybridOutput && settings.config.output === 'hybrid'; | ||
switch (true) { | ||
case settings.config.output === 'static': { | ||
settings.timer.start('Static generate'); | ||
await generatePages(opts, internals); | ||
await cleanServerOutput(opts); | ||
settings.timer.end('Static generate'); | ||
return; | ||
} | ||
case 'server': { | ||
case settings.config.output === 'server' || isHybridOutput: { | ||
settings.timer.start('Server generate'); | ||
await generatePages(opts, internals); | ||
await cleanStaticOutput(opts, internals); | ||
|
@@ -138,7 +140,9 @@ async function ssrBuild( | |
container: AstroBuildPluginContainer | ||
) { | ||
const { settings, viteConfig } = opts; | ||
const ssr = settings.config.output === 'server'; | ||
const ssr = | ||
settings.config.output === 'server' || | ||
(settings.config.experimental.hybridOutput && settings.config.output === 'hybrid'); | ||
const out = ssr ? opts.buildConfig.server : getOutDirWithinCwd(settings.config.outDir); | ||
|
||
const { lastVitePlugins, vitePlugins } = container.runBeforeHook('ssr', input); | ||
|
@@ -207,7 +211,9 @@ async function clientBuild( | |
) { | ||
const { settings, viteConfig } = opts; | ||
const timer = performance.now(); | ||
const ssr = settings.config.output === 'server'; | ||
const ssr = | ||
settings.config.output === 'server' || | ||
(settings.config.experimental.hybridOutput && settings.config.output === 'hybrid'); | ||
const out = ssr ? opts.buildConfig.client : getOutDirWithinCwd(settings.config.outDir); | ||
|
||
// Nothing to do if there is no client-side JS. | ||
|
@@ -273,7 +279,7 @@ async function runPostBuildHooks( | |
const buildConfig = container.options.settings.config.build; | ||
for (const [fileName, mutation] of mutations) { | ||
const root = | ||
config.output === 'server' | ||
config.output === 'server' || (config.experimental.hybridOutput && config.output === 'hybrid') | ||
? mutation.build === 'server' | ||
? buildConfig.server | ||
: buildConfig.client | ||
|
@@ -294,7 +300,9 @@ async function cleanStaticOutput(opts: StaticBuildOptions, internals: BuildInter | |
if (pageData.route.prerender) | ||
allStaticFiles.add(internals.pageToBundleMap.get(pageData.moduleSpecifier)); | ||
} | ||
const ssr = opts.settings.config.output === 'server'; | ||
const ssr = | ||
opts.settings.config.output === 'server' || | ||
(opts.settings.config.experimental.hybridOutput && opts.settings.config.output === 'hybrid'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code seems to be repeated a lot in the PR. What do you think about a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds like a good idea, I'll refactor this |
||
const out = ssr ? opts.buildConfig.server : getOutDirWithinCwd(opts.settings.config.outDir); | ||
// The SSR output is all .mjs files, the client output is not. | ||
const files = await glob('**/*.mjs', { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,6 +223,12 @@ export async function openConfig(configOptions: LoadConfigOptions): Promise<Open | |
} | ||
const astroConfig = await resolveConfig(userConfig, root, flags, configOptions.cmd); | ||
|
||
if (isHybridMalconfigured(astroConfig)) { | ||
throw new Error( | ||
`The "output" config option must be set to "hybrid" and "experimental.hybridOutput" must be set to true to use the hybrid output mode. Falling back to "static" output mode.` | ||
); | ||
} | ||
|
||
return { | ||
astroConfig, | ||
userConfig, | ||
|
@@ -351,3 +357,9 @@ export function mergeConfig( | |
): Record<string, any> { | ||
return mergeConfigRecursively(defaults, overrides, isRoot ? '' : '.'); | ||
} | ||
|
||
// TODO: remove after the experimetal phase when | ||
// it won't be needed to edit two config fields to enable the feature | ||
function isHybridMalconfigured(config: AstroConfig) { | ||
return config.experimental.hybridOutput ? config.output !== 'hybrid' : config.output === 'hybrid'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an example of another function that might be nice to live in a prerender folder. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vitePluginPage
runs beforevitePluginPrerender
which is responsible for parsing theprerender
metadata of astro files, so there's no way to know if there are prerendered pages or not from this stage.This would always return
undefined
so I removed it.