Skip to content
Advertisement

Configure Vue loader and lazysizes to transform urls with Nuxt

I’m trying to configure lazysizes with Nuxt and my urls are not handled by Webpack so I get a 404 error. I get the path src="~/assets/img.png" instead of src="/_nuxt/assets/img.png". I added lazysizes as an npm package and the following to my nuxt.config.js file.

JavaScript

And this content to the plugins/lazysizes.client.ts

JavaScript

For minimal reproduction, I just use a very simple image like so.

JavaScript

I worked off of this article https://dev.to/ignore_you/minify-generate-webp-and-lazyload-images-in-your-vue-nuxt-application-1ilm.

Advertisement

Answer

Found out the answer! If anyone comes here, for future reference, I solved it reading this article https://medium.com/@dannjb/a-lazy-loading-image-component-for-nuxt-js-c34e0909e6e1.

JavaScript

After removing the isClient check for SSR, I got it to work!

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement