vvo / lazyload

:bullettrain_front: Lazyload images, iframes, widgets with a standalone JavaScript lazyloader
https://vvo.github.io/lazyload/
MIT License
938 stars 158 forks source link

Usability with webpack ? #77

Closed jdeniau closed 4 months ago

jdeniau commented 7 years ago

Hi,

I'm trying to switch to webpack a big project using lazyload but as the script needs to be loaded on the top on the page, I do not manage to make it work.

The config looks like this:

module.exports = {
  entry: {
    head: [
      './custom-lazyload.js', // which does `import lazyload from 'lazyloadjs'`
    ],
    global: [
      // some files
    ]
  },
  plugins: [
    new webpack.optimize.CommonsChunkPlugin({
      name: 'vendor',
    })
  ]
}

I got tree generated files: head.js, global.js and vendor.js but the webpack "bootstrap" is in the vendor and the vendor is huge, I do not want to load it on the top of the page.

The head.js start like this: webpackJsonp([16],{ and so the webpackJsonp function does not exists.

Do you have by any change a working example with webpack ? or an idea on how to make it work ?

Thank you

vvo commented 7 years ago

Sorry never tried to do so. What I would do is inline lazyload script in the HTML page rather than trying to bundle it somehow with webpack. Dirty but works