Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative paths for srcset not working #35

Closed
2 tasks done
HerrBertling opened this issue Nov 12, 2021 · 4 comments
Closed
2 tasks done

Relative paths for srcset not working #35

HerrBertling opened this issue Nov 12, 2021 · 4 comments

Comments

@HerrBertling
Copy link

  • I have read the [troubleshooting section] before opening an issue.
  • I have tried upgrading iles and vite.

Description 📖

Hey 👋 When using a picture element, it seems as if the src for the img is resolved correctly, but the srcset attribute for different source tags is not resolved when using ~ or @.

Reproduction 🐞

<picture>
    <source
      srcset="
        @/assets/images/some_image_2x.png 2x,
        @/assets/images/some_image.png
      "
      type="image/png"
    />
    <source
      srcset="
        @/assets/images/some_image_2x.webp 2x,
        @/assets/images/some_image.webp
      "
      type="image/webp"
    />
    <img
      loading="lazy"
      src="@/assets/images/some_image.png"
    />
  </picture>

This will result in this code, at least in dev mode (haven't checked the build but my guess is that it's incorrect there as well):

<picture>
    <source
      srcset="
        /src/components/@/assets/images/some_image.png 2x,
        /src/components/@/assets/images/some_image.png"
      type="image/png"
    >
    <source
      srcset="
        /src/components/@/assets/images/some_image_2x.webp 2x,
        /src/components/@/assets/images/some_image.webp"
      type="image/webp"
    >
    <img
      loading="lazy"
      src="/src/assets/images/some_image.png"
    >
  </picture>
Dependencies Info
iles v0.6.4 vite v2.6.14
@ElMassimo
Copy link
Owner

ElMassimo commented Nov 12, 2021

Hi Markus!

îles does not alter how @vitejs/plugin-vue extracts imports or vite perform import analysis.

Since it works for src in img, it's likely that relative import detection in srcset has a bug in Vue.

Please visit the Vue Land Discord to ask about this kind of usage, or open an issue in Vue 😃


In the meantime, you can manually import the image sources and bind them:

import someImageSrc from '@/assets/images/some_image.png'
<source :srcset="someImage" type="image/png">

@ElMassimo
Copy link
Owner

@HerrBertling About your question about global CSS, the best approach is to import it in src/app.ts. Plan to document this soon in a Recipes section in the docs.

See the following examples:

@ElMassimo
Copy link
Owner

ElMassimo commented Nov 12, 2021

@HerrBertling This is the relevant code regarding srcset transforms in Vue.

Looks like there are several PRs open in Vue to patch this or similar problems:

@HerrBertling
Copy link
Author

Wow. Thanks for the answers ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants