mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
Feat/ssr manifest (#3262)
* feat: expose pagesVirtualModuleId * feat: add astro:build:ssr hook * fix: missing import for pagesVirtualModuleId * test: fix tests * refactor: move exports to index.ts * chore: changeset
This commit is contained in:
parent
dd9ffc317f
commit
adada1ba01
7 changed files with 34 additions and 9 deletions
5
.changeset/twelve-onions-warn.md
Normal file
5
.changeset/twelve-onions-warn.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Adds astro:build:ssr integration hook
|
|
@ -13,6 +13,7 @@ import type {
|
|||
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';
|
||||
export type { SSRManifest } from '../core/app/types';
|
||||
|
||||
export interface AstroBuiltinProps {
|
||||
|
@ -907,6 +908,7 @@ export interface AstroIntegration {
|
|||
'astro:server:setup'?: (options: { server: vite.ViteDevServer }) => void | Promise<void>;
|
||||
'astro:server:start'?: (options: { address: AddressInfo }) => void | Promise<void>;
|
||||
'astro:server:done'?: () => void | Promise<void>;
|
||||
'astro:build:ssr'?: (options: { manifest: SerializedSSRManifest }) => void | Promise<void>;
|
||||
'astro:build:start'?: (options: { buildConfig: BuildConfig }) => void | Promise<void>;
|
||||
'astro:build:setup'?: (options: {
|
||||
vite: ViteConfigWithSSR;
|
||||
|
|
|
@ -20,6 +20,9 @@ import {
|
|||
} from '../render/ssr-element.js';
|
||||
import { prependForwardSlash } from '../path.js';
|
||||
|
||||
export const pagesVirtualModuleId = '@astrojs-pages-virtual-entry';
|
||||
export const resolvedPagesVirtualModuleId = '\0' + pagesVirtualModuleId;
|
||||
|
||||
export class App {
|
||||
#manifest: Manifest;
|
||||
#manifestData: ManifestData;
|
||||
|
|
|
@ -4,9 +4,7 @@ import type { StaticBuildOptions } from './types';
|
|||
import { addRollupInput } from './add-rollup-input.js';
|
||||
import { eachPageData } from './internal.js';
|
||||
import { isBuildingToSSR } from '../util.js';
|
||||
|
||||
export const virtualModuleId = '@astrojs-pages-virtual-entry';
|
||||
export const resolvedVirtualModuleId = '\0' + virtualModuleId;
|
||||
import { resolvedPagesVirtualModuleId, pagesVirtualModuleId } from '../app/index.js';
|
||||
|
||||
export function vitePluginPages(opts: StaticBuildOptions, internals: BuildInternals): VitePlugin {
|
||||
return {
|
||||
|
@ -14,18 +12,18 @@ export function vitePluginPages(opts: StaticBuildOptions, internals: BuildIntern
|
|||
|
||||
options(options) {
|
||||
if (!isBuildingToSSR(opts.astroConfig)) {
|
||||
return addRollupInput(options, [virtualModuleId]);
|
||||
return addRollupInput(options, [pagesVirtualModuleId]);
|
||||
}
|
||||
},
|
||||
|
||||
resolveId(id) {
|
||||
if (id === virtualModuleId) {
|
||||
return resolvedVirtualModuleId;
|
||||
if (id === pagesVirtualModuleId) {
|
||||
return resolvedPagesVirtualModuleId;
|
||||
}
|
||||
},
|
||||
|
||||
load(id) {
|
||||
if (id === resolvedVirtualModuleId) {
|
||||
if (id === resolvedPagesVirtualModuleId) {
|
||||
let importMap = '';
|
||||
let imports = [];
|
||||
let i = 0;
|
||||
|
|
|
@ -9,8 +9,9 @@ import { eachPageData } from './internal.js';
|
|||
import { addRollupInput } from './add-rollup-input.js';
|
||||
import { fileURLToPath } from 'url';
|
||||
import glob from 'fast-glob';
|
||||
import { virtualModuleId as pagesVirtualModuleId } from './vite-plugin-pages.js';
|
||||
import { pagesVirtualModuleId } from '../app/index.js';
|
||||
import { BEFORE_HYDRATION_SCRIPT_ID } from '../../vite-plugin-scripts/index.js';
|
||||
import { runHookBuildSsr } from '../../integrations/index.js';
|
||||
|
||||
export const virtualModuleId = '@astrojs-ssr-virtual-entry';
|
||||
const resolvedVirtualModuleId = '\0' + virtualModuleId;
|
||||
|
@ -73,6 +74,7 @@ if(_start in adapter) {
|
|||
});
|
||||
|
||||
const manifest = buildManifest(buildOpts, internals, staticFiles);
|
||||
await runHookBuildSsr({config: buildOpts.astroConfig, manifest});
|
||||
|
||||
for (const [_chunkName, chunk] of Object.entries(bundle)) {
|
||||
if (chunk.type === 'asset') {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import type { AddressInfo } from 'net';
|
||||
import type { ViteDevServer } from 'vite';
|
||||
import type { SerializedSSRManifest } from '../core/app/types';
|
||||
import { AstroConfig, AstroRenderer, BuildConfig, RouteData } from '../@types/astro.js';
|
||||
import { mergeConfig } from '../core/config.js';
|
||||
import ssgAdapter from '../adapter-ssg/index.js';
|
||||
|
@ -135,6 +136,20 @@ export async function runHookBuildSetup({
|
|||
}
|
||||
}
|
||||
|
||||
export async function runHookBuildSsr({
|
||||
config,
|
||||
manifest,
|
||||
}: {
|
||||
config: AstroConfig;
|
||||
manifest: SerializedSSRManifest;
|
||||
}) {
|
||||
for (const integration of config.integrations) {
|
||||
if (integration.hooks['astro:build:ssr']) {
|
||||
await integration.hooks['astro:build:ssr']({ manifest });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function runHookBuildDone({
|
||||
config,
|
||||
buildConfig,
|
||||
|
|
|
@ -8,7 +8,7 @@ import { fileURLToPath } from 'url';
|
|||
import type { Plugin } from 'vite';
|
||||
import type { AstroConfig } from '../@types/astro';
|
||||
import { PAGE_SSR_SCRIPT_ID } from '../vite-plugin-scripts/index.js';
|
||||
import { virtualModuleId as pagesVirtualModuleId } from '../core/build/vite-plugin-pages.js';
|
||||
import { pagesVirtualModuleId } from '../core/app/index.js';
|
||||
import { appendForwardSlash } from '../core/path.js';
|
||||
import { resolvePages } from '../core/util.js';
|
||||
|
||||
|
|
Loading…
Reference in a new issue