From c039ea93a1372d954f924a1e6a019a834d1eeb7a Mon Sep 17 00:00:00 2001 From: Corbin Crutchley Date: Fri, 5 Aug 2022 16:56:12 -0700 Subject: [PATCH] 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 --- .changeset/rude-falcons-smash.md | 5 +++++ packages/integrations/image/src/lib/get-image.ts | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changeset/rude-falcons-smash.md diff --git a/.changeset/rude-falcons-smash.md b/.changeset/rude-falcons-smash.md new file mode 100644 index 000000000..f27922395 --- /dev/null +++ b/.changeset/rude-falcons-smash.md @@ -0,0 +1,5 @@ +--- +'@astrojs/image': patch +--- + +Enable usage outside of vite contexts, such as the config file diff --git a/packages/integrations/image/src/lib/get-image.ts b/packages/integrations/image/src/lib/get-image.ts index 9ec58795b..c295831a3 100644 --- a/packages/integrations/image/src/lib/get-image.ts +++ b/packages/integrations/image/src/lib/get-image.ts @@ -117,8 +117,9 @@ export async function getImage( const attributes = await loader.getImageAttributes(resolved); + // `.env` must be optional to support running in environments outside of `vite` (such as `astro.config`) // @ts-ignore - const isDev = import.meta.env.DEV; + const isDev = import.meta.env?.DEV; const isLocalImage = !isRemoteImage(resolved.src); const _loader = isDev && isLocalImage ? sharp : loader;