Fix build output in static build mode (#2358)

* Fix build output in static build mode

* Adds a changeset

* Formatting
This commit is contained in:
Matthew Phillips 2022-01-11 11:24:57 -05:00 committed by GitHub
parent f482c626a6
commit 1007497297
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes the output when using the experimental-static-build flag

View file

@ -101,6 +101,7 @@ class AstroBuilder {
astroConfig: this.config,
logging: this.logging,
origin: this.origin,
pageNames,
routeCache: this.routeCache,
viteConfig: this.viteConfig,
});

View file

@ -25,10 +25,16 @@ export interface StaticBuildOptions {
astroConfig: AstroConfig;
logging: LogOptions;
origin: string;
pageNames: string[];
routeCache: RouteCache;
viteConfig: ViteConfigWithSSR;
}
function addPageName(pathname: string, opts: StaticBuildOptions): void {
const pathrepl = opts.astroConfig.buildOptions.pageUrlFormat === 'directory' ? '/index.html' : pathname === '/' ? 'index.html' : '.html';
opts.pageNames.push(pathname.replace(/\/?$/, pathrepl).replace(/^\//, ''));
}
export async function staticBuild(opts: StaticBuildOptions) {
const { allPages, astroConfig } = opts;
@ -198,9 +204,12 @@ interface GeneratePathOptions {
}
async function generatePath(pathname: string, opts: StaticBuildOptions, gopts: GeneratePathOptions) {
const { astroConfig, logging, origin, routeCache } = opts;
const { astroConfig, logging, origin, pageNames, routeCache } = opts;
const { Component, internals, linkIds, pageData } = gopts;
// This adds the page name to the array so it can be shown as part of stats.
addPageName(pathname, opts);
const [renderers, mod] = pageData.preload;
try {