Skip to content

Commit

Permalink
Fix external astro image usage (#4147)
Browse files Browse the repository at this point in the history
* fix: enable @astrojs/image to be used inside of non-vite contexts

* chore: add changeset

Co-authored-by: Nate Moore <[email protected]>
  • Loading branch information
crutchcorn and natemoo-re authored Aug 5, 2022
1 parent 2675b86 commit c039ea9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/rude-falcons-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/image': patch
---

Enable usage outside of vite contexts, such as the config file
3 changes: 2 additions & 1 deletion packages/integrations/image/src/lib/get-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c039ea9

Please sign in to comment.