Allow "absolute path" and/or aliases usage with StaticImage #35667
Replies: 5 comments
-
Yes this is by design as we in general only support relative paths. Do you have a specific need for absolute paths? |
Beta Was this translation helpful? Give feedback.
-
Well, it's just much simpler to type a path starting in |
Beta Was this translation helpful? Give feedback.
-
I'll re-clasify this as a feature request (not bug report), due to the way it works now is intentional. I can see potential value in supporting "paths relative to root" or aliases, but not supporting them is NOT a bug. Code wise - here's where we generate full path Where
Webpack doesn't take part in StaticImage handling - we only do babel transform, so aliases defined for webpack just can't work. There possibly are other ways to define aliases (not scoped to webpack) that might be potentially used to achieve this feature |
Beta Was this translation helpful? Give feedback.
-
Is there a proposed solution to this feature request? |
Beta Was this translation helpful? Give feedback.
-
This approach also disallows to pass src as variable. This doesn't work: import src from 'src/images/some.png'
<StaticImage src={src} /> (because imported path will be like And even this doesn't work! const src = '../../images/some.png'
<StaticImage src={src} /> If I have multiple images with numerous options which differ only by And even It's just a majorly inconvenient api in all regards. |
Beta Was this translation helpful? Give feedback.
-
Description
StaticImage
, fromgatsby-plugin-image
, only seems to work when thesrc
is specified as a relative file path, such as../../images/Filter.png
. It fails with a path like/src/images/Filter.png
. It also doesn't support webpack aliases.Beta Was this translation helpful? Give feedback.
All reactions