diff --git a/packages/astro/src/assets/types.ts b/packages/astro/src/assets/types.ts index 71362ef95248..9c5990cb77ae 100644 --- a/packages/astro/src/assets/types.ts +++ b/packages/astro/src/assets/types.ts @@ -97,7 +97,7 @@ export type LocalImageProps = ImageSharedProps & { * ... * ``` */ - src: ImageMetadata; + src: ImageMetadata | Promise<{ default: ImageMetadata }>; /** * Desired output format for the image. Defaults to `webp`. * diff --git a/packages/astro/test/core-image.test.js b/packages/astro/test/core-image.test.js index 4d5f467bfc0f..8c09de245211 100644 --- a/packages/astro/test/core-image.test.js +++ b/packages/astro/test/core-image.test.js @@ -147,6 +147,19 @@ describe('astro:image', () => { }) ).to.be.true; }); + + it('supports inlined imports', async () => { + let res = await fixture.fetch('/inlineImport'); + let html = await res.text(); + $ = cheerio.load(html); + + let $img = $('img'); + expect($img).to.have.a.lengthOf(1); + + let src = $img.attr('src'); + res = await fixture.fetch(src); + expect(res.status).to.equal(200); + }); }); describe('vite-isms', () => { diff --git a/packages/astro/test/fixtures/core-image/src/pages/inlineImport.astro b/packages/astro/test/fixtures/core-image/src/pages/inlineImport.astro new file mode 100644 index 000000000000..3235879934c3 --- /dev/null +++ b/packages/astro/test/fixtures/core-image/src/pages/inlineImport.astro @@ -0,0 +1,7 @@ +--- +import { getImage } from "astro:assets"; + +const optimizedImage = await getImage({src: import('../assets/penguin1.jpg')}) +--- + +