zerodevx / svelte-img

High-performance responsive/progressive images for SvelteKit
https://zerodevx.github.io/svelte-img/
ISC License
300 stars 11 forks source link

Any way to avoid loading FxParallax assets? #27

Closed phaberest closed 11 months ago

phaberest commented 11 months ago

I see that the css for FxParallax is adding an item to my request chain and since I am not using any of its features in this project I would like to disable it and just keep the Img side, is there any way to do it?

I imported as import Img from '@zerodevx/svelte-img' everywhere

zerodevx commented 11 months ago

I don't quite understand your question tbh?

<script>
  import Img, { FxParallax } from '@zerodevx/svelte-img'
  import src from '$lib/a/cat.jpg?as=run'
</script>

<!-- Img component -->
<Img {src} />

<!-- Img component with Parallax -->
<FxParallax {src} />

Edit: oh do you mean FxParallax is not tree-shaken away? If you didn't import FxParallax at all in your project, then its related code should be automatically excluded from your build.

phaberest commented 11 months ago

Thank you @zerodevx, that's exactly what I mean. I never used it anywhere in the project, but it's getting loaded in the final build anyway.

I installed it as usual, no difference from standard edits to vite.config.js for imagetools and importing Img where needed.

But as you can see, it is part of the bundle: https://nexuser.it/_app/immutable/chunks/FxParallax.svelte_svelte_type_style_lang.2717a0f6.js

zerodevx commented 11 months ago

Hey, so two things:

But as you can see, it is part of the bundle: https://nexuser.it/_app/immutable/chunks/FxParallax.svelte_svelte_type_style_lang.2717a0f6.js

Firstly, this chunk includes code from v1 - they are removed from v2. Could you check that you're on @zerodevx/svelte-img@2?

Secondly, I tried reproducing this on a fresh project and can confirm that I did get a build chunk named FxParallax.svelte*.js - despite not importing the parallax component anywhere. I'm still investigating, but AFAICT, the actual FxParallax code isn't anywhere in the chunk. So I'm inclined to think that it's just a badly named tree-shaken chunk. 🤷

Edit: can confirm that FxParallax is not tree-shaken away - surprised why that's happening tbh.

zerodevx commented 11 months ago

This should be fixed with v2.0.2. Thanks for bringing this to attention - great catch! 👍