0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Fix external astro image usage (#4147)

* fix: enable @astrojs/image to be used inside of non-vite contexts

* chore: add changeset

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
Corbin Crutchley 2022-08-05 16:56:12 -07:00 committed by GitHub
parent 2675b8633c
commit c039ea93a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/image': patch
---
Enable usage outside of vite contexts, such as the config file

View file

@ -117,8 +117,9 @@ export async function getImage(
const attributes = await loader.getImageAttributes(resolved); const attributes = await loader.getImageAttributes(resolved);
// `.env` must be optional to support running in environments outside of `vite` (such as `astro.config`)
// @ts-ignore // @ts-ignore
const isDev = import.meta.env.DEV; const isDev = import.meta.env?.DEV;
const isLocalImage = !isRemoteImage(resolved.src); const isLocalImage = !isRemoteImage(resolved.src);
const _loader = isDev && isLocalImage ? sharp : loader; const _loader = isDev && isLocalImage ? sharp : loader;