adds a new astro:build:generated
hook for SSG builds
This commit is contained in:
parent
d2bfbac91c
commit
59b5fec7be
5 changed files with 29 additions and 4 deletions
|
@ -1149,6 +1149,7 @@ export interface AstroIntegration {
|
|||
'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:generated'?: (options: { dir: URL }) => void | Promise<void>;
|
||||
'astro:build:start'?: (options: { buildConfig: BuildConfig }) => void | Promise<void>;
|
||||
'astro:build:setup'?: (options: {
|
||||
vite: ViteConfigWithSSR;
|
||||
|
|
|
@ -6,7 +6,7 @@ import * as vite from 'vite';
|
|||
import { BuildInternals, createBuildInternals } from '../../core/build/internal.js';
|
||||
import { prependForwardSlash } from '../../core/path.js';
|
||||
import { emptyDir, isModeServerWithNoAdapter, removeDir } from '../../core/util.js';
|
||||
import { runHookBuildSetup } from '../../integrations/index.js';
|
||||
import { runHookBuildGenerated, runHookBuildSetup } from '../../integrations/index.js';
|
||||
import { PAGE_SCRIPT_ID } from '../../vite-plugin-scripts/index.js';
|
||||
import type { ViteConfigWithSSR } from '../create-vite';
|
||||
import { info } from '../logger/core.js';
|
||||
|
@ -98,6 +98,7 @@ Learn more: https://docs.astro.build/en/guides/server-side-rendering/
|
|||
timer.generate = performance.now();
|
||||
if (astroConfig.output === 'static') {
|
||||
await generatePages(opts, internals);
|
||||
await runHookBuildGenerated({ config: opts.astroConfig, buildConfig: opts.buildConfig, logging: opts.logging });
|
||||
await cleanSsrOutput(opts);
|
||||
} else {
|
||||
// Inject the manifest
|
||||
|
|
|
@ -243,6 +243,28 @@ export async function runHookBuildSetup({
|
|||
}
|
||||
}
|
||||
|
||||
export async function runHookBuildGenerated({
|
||||
config,
|
||||
buildConfig,
|
||||
logging,
|
||||
}: {
|
||||
config: AstroConfig,
|
||||
buildConfig: BuildConfig,
|
||||
logging: LogOptions,
|
||||
}) {
|
||||
const dir = config.output === 'server' ? buildConfig.client : config.outDir;
|
||||
|
||||
for (const integration of config.integrations) {
|
||||
if (integration?.hooks?.['astro:build:generated']) {
|
||||
await withTakingALongTimeMsg({
|
||||
name: integration.name,
|
||||
hookResult: integration.hooks['astro:build:generated']({ dir }),
|
||||
logging,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function runHookBuildSsr({
|
||||
config,
|
||||
manifest,
|
||||
|
|
|
@ -105,7 +105,7 @@ export default function integration(options: IntegrationOptions = {}): AstroInte
|
|||
}
|
||||
: {};
|
||||
},
|
||||
'astro:build:done': async ({ dir }) => {
|
||||
'astro:build:generated': async ({ dir }) => {
|
||||
if (resolvedOptions.serviceEntryPoint === '@astrojs/image/squoosh') {
|
||||
await copyWasmFiles(_config.output === 'static' ? dir : _buildConfig.server);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { cpus } from 'os'
|
||||
import { cpus } from 'node:os'
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { isMainThread } from 'node:worker_threads';
|
||||
import WorkerPool from '../../utils/workerPool.js';
|
||||
import * as impl from './impl.js';
|
||||
|
@ -22,7 +23,7 @@ const getWorker = execOnce(
|
|||
// There will be at most 7 workers needed since each worker will take
|
||||
// at least 1 operation type.
|
||||
Math.max(1, Math.min(cpus().length - 1, 7)),
|
||||
'./node_modules/@astrojs/image/dist/vendor/squoosh/image-pool.js'
|
||||
fileURLToPath(import.meta.url)
|
||||
);
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue