diff options
author | 2022-08-05 16:56:12 -0700 | |
---|---|---|
committer | 2022-08-05 18:56:12 -0500 | |
commit | c039ea93a1372d954f924a1e6a019a834d1eeb7a (patch) | |
tree | 35ae6141a45e8474a24440519ec0be8bdbed85f3 | |
parent | 2675b8633c5d5c45b237ec87940d5eaf1bfb1b4b (diff) | |
download | astro-c039ea93a1372d954f924a1e6a019a834d1eeb7a.tar.gz astro-c039ea93a1372d954f924a1e6a019a834d1eeb7a.tar.zst astro-c039ea93a1372d954f924a1e6a019a834d1eeb7a.zip |
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>
-rw-r--r-- | .changeset/rude-falcons-smash.md | 5 | ||||
-rw-r--r-- | packages/integrations/image/src/lib/get-image.ts | 3 |
2 files changed, 7 insertions, 1 deletions
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; |