mirror of
https://github.com/withastro/astro.git
synced 2025-01-20 22:12:38 -05:00
Make prerendering decision based on PageBuildData
instead of BuildInternals
(#6956)
* read prerender flag from PageBuildData * add changeset
This commit is contained in:
parent
895fa07d8b
commit
367e617761
5 changed files with 20 additions and 32 deletions
5
.changeset/popular-bats-pump.md
Normal file
5
.changeset/popular-bats-pump.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Changed where various parts of the build pipeline look to decide if a page should be prerendered. They now exclusively consider PageBuildData, allowing integrations to participate in the decision.
|
|
@ -39,12 +39,7 @@ import { createRequest } from '../request.js';
|
||||||
import { matchRoute } from '../routing/match.js';
|
import { matchRoute } from '../routing/match.js';
|
||||||
import { getOutputFilename } from '../util.js';
|
import { getOutputFilename } from '../util.js';
|
||||||
import { getOutDirWithinCwd, getOutFile, getOutFolder } from './common.js';
|
import { getOutDirWithinCwd, getOutFile, getOutFolder } from './common.js';
|
||||||
import {
|
import { eachPageData, getPageDataByComponent, sortedCSS } from './internal.js';
|
||||||
eachPageData,
|
|
||||||
eachPrerenderedPageData,
|
|
||||||
getPageDataByComponent,
|
|
||||||
sortedCSS,
|
|
||||||
} from './internal.js';
|
|
||||||
import type { PageBuildData, SingleFileBuiltModule, StaticBuildOptions } from './types';
|
import type { PageBuildData, SingleFileBuiltModule, StaticBuildOptions } from './types';
|
||||||
import { getTimeStat } from './util.js';
|
import { getTimeStat } from './util.js';
|
||||||
|
|
||||||
|
@ -99,8 +94,9 @@ export async function generatePages(opts: StaticBuildOptions, internals: BuildIn
|
||||||
const builtPaths = new Set<string>();
|
const builtPaths = new Set<string>();
|
||||||
|
|
||||||
if (ssr) {
|
if (ssr) {
|
||||||
for (const pageData of eachPrerenderedPageData(internals)) {
|
for (const pageData of eachPageData(internals)) {
|
||||||
await generatePage(opts, internals, pageData, ssrEntry, builtPaths);
|
if (pageData.route.prerender)
|
||||||
|
await generatePage(opts, internals, pageData, ssrEntry, builtPaths);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (const pageData of eachPageData(internals)) {
|
for (const pageData of eachPageData(internals)) {
|
||||||
|
|
|
@ -216,30 +216,14 @@ export function* eachPageData(internals: BuildInternals) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hasPrerenderedPages(internals: BuildInternals) {
|
export function hasPrerenderedPages(internals: BuildInternals) {
|
||||||
for (const id of internals.pagesByViteID.keys()) {
|
for (const pageData of eachPageData(internals)) {
|
||||||
if (internals.pageOptionsByPage.get(id)?.prerender) {
|
if (pageData.route.prerender) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function* eachPrerenderedPageData(internals: BuildInternals) {
|
|
||||||
for (const [id, pageData] of internals.pagesByViteID.entries()) {
|
|
||||||
if (internals.pageOptionsByPage.get(id)?.prerender) {
|
|
||||||
yield pageData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* eachServerPageData(internals: BuildInternals) {
|
|
||||||
for (const [id, pageData] of internals.pagesByViteID.entries()) {
|
|
||||||
if (!internals.pageOptionsByPage.get(id)?.prerender) {
|
|
||||||
yield pageData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort a page's CSS by depth. A higher depth means that the CSS comes from shared subcomponents.
|
* Sort a page's CSS by depth. A higher depth means that the CSS comes from shared subcomponents.
|
||||||
* A lower depth means it comes directly from the top-level page.
|
* A lower depth means it comes directly from the top-level page.
|
||||||
|
|
|
@ -13,7 +13,7 @@ import { joinPaths, prependForwardSlash } from '../../path.js';
|
||||||
import { serializeRouteData } from '../../routing/index.js';
|
import { serializeRouteData } from '../../routing/index.js';
|
||||||
import { addRollupInput } from '../add-rollup-input.js';
|
import { addRollupInput } from '../add-rollup-input.js';
|
||||||
import { getOutFile, getOutFolder } from '../common.js';
|
import { getOutFile, getOutFolder } from '../common.js';
|
||||||
import { eachPrerenderedPageData, eachServerPageData, sortedCSS } from '../internal.js';
|
import { eachPageData, sortedCSS } from '../internal.js';
|
||||||
import type { AstroBuildPlugin } from '../plugin';
|
import type { AstroBuildPlugin } from '../plugin';
|
||||||
|
|
||||||
export const virtualModuleId = '@astrojs-ssr-virtual-entry';
|
export const virtualModuleId = '@astrojs-ssr-virtual-entry';
|
||||||
|
@ -142,7 +142,8 @@ function buildManifest(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const pageData of eachPrerenderedPageData(internals)) {
|
for (const pageData of eachPageData(internals)) {
|
||||||
|
if (!pageData.route.prerender) continue;
|
||||||
if (!pageData.route.pathname) continue;
|
if (!pageData.route.pathname) continue;
|
||||||
|
|
||||||
const outFolder = getOutFolder(
|
const outFolder = getOutFolder(
|
||||||
|
@ -166,7 +167,8 @@ function buildManifest(
|
||||||
staticFiles.push(file);
|
staticFiles.push(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const pageData of eachServerPageData(internals)) {
|
for (const pageData of eachPageData(internals)) {
|
||||||
|
if (pageData.route.prerender) continue;
|
||||||
const scripts: SerializedRouteInfo['scripts'] = [];
|
const scripts: SerializedRouteInfo['scripts'] = [];
|
||||||
if (pageData.hoistedScript) {
|
if (pageData.hoistedScript) {
|
||||||
const hoistedValue = pageData.hoistedScript.value;
|
const hoistedValue = pageData.hoistedScript.value;
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { fileURLToPath } from 'url';
|
||||||
import * as vite from 'vite';
|
import * as vite from 'vite';
|
||||||
import {
|
import {
|
||||||
createBuildInternals,
|
createBuildInternals,
|
||||||
eachPrerenderedPageData,
|
eachPageData,
|
||||||
type BuildInternals,
|
type BuildInternals,
|
||||||
} from '../../core/build/internal.js';
|
} from '../../core/build/internal.js';
|
||||||
import { emptyDir, removeEmptyDirs } from '../../core/fs/index.js';
|
import { emptyDir, removeEmptyDirs } from '../../core/fs/index.js';
|
||||||
|
@ -290,8 +290,9 @@ async function runPostBuildHooks(
|
||||||
*/
|
*/
|
||||||
async function cleanStaticOutput(opts: StaticBuildOptions, internals: BuildInternals) {
|
async function cleanStaticOutput(opts: StaticBuildOptions, internals: BuildInternals) {
|
||||||
const allStaticFiles = new Set();
|
const allStaticFiles = new Set();
|
||||||
for (const pageData of eachPrerenderedPageData(internals)) {
|
for (const pageData of eachPageData(internals)) {
|
||||||
allStaticFiles.add(internals.pageToBundleMap.get(pageData.moduleSpecifier));
|
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';
|
||||||
const out = ssr ? opts.buildConfig.server : getOutDirWithinCwd(opts.settings.config.outDir);
|
const out = ssr ? opts.buildConfig.server : getOutDirWithinCwd(opts.settings.config.outDir);
|
||||||
|
|
Loading…
Add table
Reference in a new issue