kavu / webp-loader

WebP image loader & converter for Webpack
MIT License
93 stars 17 forks source link

Generate both images (jpg/png and webp) with hash. #8

Closed alizhdanov closed 5 years ago

alizhdanov commented 6 years ago

Hi,

I'm trying to generate alternate versions for my images, which is working fine. However, when I'm trying add hashes , I'm getting a problem.

I'm using part of code from README but adding [hash] placeholder

loaders: [
  {
    test: /\.(jpe?g|png)$/i,
    loader: multi(
      'file-loader?name=[name].[hash].webp!webp-loader?{quality: 95}'
      'file-loader?name=[name].[hash].[ext]',
    )
  },
]

Which is working, but generating different hashes

So output will be:

image.12345.jpg
image.67890.webp

Can I somehow generate img's with same hashes, like this:

image.12345.jpg
image.12345.webp

Thanks

kavu commented 6 years ago

Thank you for your report! I will investigate it.

Meanwhile, can you tell what exact version of Webpack do you use? Thanks!

alizhdanov commented 6 years ago

Meanwhile, can you tell what exact version of Webpack do you use? Thanks!

  • webpack 3.9.1
  • file-loader 1.1.5
  • webp-loader 0.2.1
kavu commented 5 years ago

I investigated this issue again and, unfortunately, I think it is not possible. File hashing is done for specific content, and it is done deep inside loader-utils.

The only thing I can suggest here is something like that, pretty common pattern:

loaders: [
  {
    test: /\.(jpe?g|png)$/i,
    loader: multi(
      'file-loader?name=[name].webp?[hash]!webp-loader?{quality: 95}'
      'file-loader?name=[name].[ext]?[hash]',
    )
  },
]