feat: expose pages (#3286)

* feat: expose pages

* chore: changeset

* fix: build
This commit is contained in:
Pascal Schilp 2022-05-04 14:27:51 +02:00 committed by GitHub
parent 8de641cb7f
commit e5f6de4edb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Adds pages param to the astro:build:setup integration hook

View file

@ -14,6 +14,7 @@ import type { AstroConfigSchema } from '../core/config';
import type { AstroComponentFactory, Metadata } from '../runtime/server';
import type { ViteConfigWithSSR } from '../core/create-vite';
import type { SerializedSSRManifest } from '../core/app/types';
import type { PageBuildData } from '../core/build/types';
export type { SSRManifest } from '../core/app/types';
export interface AstroBuiltinProps {
@ -912,8 +913,9 @@ export interface AstroIntegration {
'astro:build:start'?: (options: { buildConfig: BuildConfig }) => void | Promise<void>;
'astro:build:setup'?: (options: {
vite: ViteConfigWithSSR;
pages: Map<string, PageBuildData>;
target: 'client' | 'server';
}) => void;
}) => void | Promise<void>;
'astro:build:done'?: (options: {
pages: { pathname: string }[];
dir: URL;

View file

@ -167,7 +167,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
resolve: viteConfig.resolve,
} as ViteConfigWithSSR;
await runHookBuildSetup({ config: astroConfig, vite: viteBuildConfig, target: 'server' });
await runHookBuildSetup({ config: astroConfig, pages: internals.pagesByComponent, vite: viteBuildConfig, target: 'server' });
// TODO: use vite.mergeConfig() here?
return await vite.build(viteBuildConfig);
@ -232,7 +232,7 @@ async function clientBuild(
base: astroConfig.base,
} as ViteConfigWithSSR;
await runHookBuildSetup({ config: astroConfig, vite: viteBuildConfig, target: 'client' });
await runHookBuildSetup({ config: astroConfig, pages: internals.pagesByComponent, vite: viteBuildConfig, target: 'client' });
const buildResult = await vite.build(viteBuildConfig);
info(opts.logging, null, dim(`Completed in ${getTimeStat(timer, performance.now())}.\n`));

View file

@ -1,6 +1,7 @@
import type { AddressInfo } from 'net';
import type { ViteDevServer } from 'vite';
import type { SerializedSSRManifest } from '../core/app/types';
import type { PageBuildData } from '../core/build/types';
import { AstroConfig, AstroRenderer, BuildConfig, RouteData } from '../@types/astro.js';
import { mergeConfig } from '../core/config.js';
import ssgAdapter from '../adapter-ssg/index.js';
@ -123,15 +124,17 @@ export async function runHookBuildStart({
export async function runHookBuildSetup({
config,
vite,
pages,
target,
}: {
config: AstroConfig;
vite: ViteConfigWithSSR;
pages: Map<string, PageBuildData>;
target: 'server' | 'client';
}) {
for (const integration of config.integrations) {
if (integration.hooks['astro:build:setup']) {
await integration.hooks['astro:build:setup']({ vite, target });
await integration.hooks['astro:build:setup']({ vite, pages, target });
}
}
}