diff --git a/packages/astro/src/assets/utils/metadata.ts b/packages/astro/src/assets/utils/metadata.ts index 8cf0cc470..710e758d9 100644 --- a/packages/astro/src/assets/utils/metadata.ts +++ b/packages/astro/src/assets/utils/metadata.ts @@ -1,4 +1,3 @@ -import sizeOf from 'image-size'; import fs from 'node:fs/promises'; import { fileURLToPath } from 'node:url'; import { ImageMetadata, InputFormat } from '../types.js'; @@ -7,10 +6,14 @@ export interface Metadata extends ImageMetadata { orientation?: number; } +let sizeOf: typeof import('image-size').default | undefined; export async function imageMetadata( src: URL | string, data?: Buffer ): Promise { + if (!sizeOf) { + sizeOf = await import('image-size').then(mod => mod.default); + } let file = data; if (!file) { try { @@ -20,7 +23,7 @@ export async function imageMetadata( } } - const { width, height, type, orientation } = await sizeOf(file); + const { width, height, type, orientation } = await sizeOf!(file); const isPortrait = (orientation || 0) >= 5; if (!width || !height || !type) {