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

data-src doesn't load images from assets folder #2650

Closed
hackuun opened this issue Jan 20, 2018 · 8 comments
Closed

data-src doesn't load images from assets folder #2650

hackuun opened this issue Jan 20, 2018 · 8 comments
Labels

Comments

@hackuun
Copy link

hackuun commented Jan 20, 2018

I am using great https://github.com/aFarkas/lazysizes package

It need such code

    <img data-src="~assets/images/kitten-large.png" class="lazyload lazy" />

But with data-src attribute Nuxt doesn't load images.
What should I do?

This question is available on Nuxt.js community (#c2305)
@NicoPennec
Copy link

Try to move your images to /static/images folder and use this path :

<img data-src="/images/kitten-large.png" class="lazyload lazy">

The assets directory should contain only your un-compiled assets such as LESS, SASS, or JS.

@hackuun
Copy link
Author

hackuun commented Jan 21, 2018

@NicoPennec yes this is working from static or from another domain, but I am wondering why t doesnt work from aasets? I have images in assets and Nuxt/webpack using them succesfully. Why you said I shouldn't store images there? Otherwise I can't use base64 inlining, for example.

@hackuun
Copy link
Author

hackuun commented Jan 21, 2018

Other words, I guess I need to store only small images in assets that I want to proceed with webpack? Right?

@hackuun
Copy link
Author

hackuun commented Jan 21, 2018

Also, I have other plugins that use custom attributes to load images - and they working fine with images from assets. How to make this particular package to work? I mean, it's best in class solution, it whould be nice to make it work properly with Nuxt.

@clarkdo
Copy link
Member

clarkdo commented Jan 24, 2018

You can add data-src to transformToRequire via build.extend in nuxt.config.js

module.exports = {
  build: {
    extend(config, { isDev }) {
      const vueLoader = config.module.rules.find((rule) => rule.loader === 'vue-loader')
      vueLoader.options.transformToRequire['img'] = ['src', 'data-src']
    }
  }
}

@clarkdo clarkdo closed this as completed Jan 24, 2018
valeriosillari added a commit to valeriosillari/zitronenstrasse that referenced this issue Mar 15, 2018
valeriosillari added a commit to valeriosillari/zitronenstrasse that referenced this issue Mar 16, 2018
solution here, latest answer by clarkdo commented on 24 Jan
nuxt/nuxt#2650
@shindeefranco
Copy link

Any feedback on this?

@clarkdo
Copy link
Member

clarkdo commented Jul 17, 2018

@shindeefranco
Hope this can help you #2008 (comment)

@lock
Copy link

lock bot commented Nov 1, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 1, 2018
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants