imagemin-webp-webpack-plugin icon indicating copy to clipboard operation
imagemin-webp-webpack-plugin copied to clipboard

Make this plugin work with 'css-loader'

Open iampava opened this issue 3 years ago • 3 comments

Unfortunately this plugin doesn't "play nice" with css-loader.

Trying to use .webp images from CSS will fail unless the url: false option is set for css-loader. For example, this code:

body {
  backgrund-image: url('/assets/cover.webp')
}

will fail since initially only cover.jpg exists, and cover.webp is created dynamically by this Plugin.

Potential fixes:

  1. use url: false option for css-loader (however this might be incompatible if your projects depends on creating the assets via this loader)
  2. have a pre-webpack step which generates the images, not part of the Webpack config. This way, the .webp files exist beforehand.

Option 2 will take some work so please up-vote this issue, this way I know how many people are affected by this problem and can prioritize accordingly.

iampava avatar Jul 19 '21 19:07 iampava

How is it going?

Alfred-wen avatar Jul 28 '22 02:07 Alfred-wen

For me it also doesn't work in a JS file with require('./images/imgname.webp'). It complains as well:

Module not found: Error: Can't resolve './images/imgname.webp' in '{local path}'

osartun avatar Mar 14 '23 15:03 osartun

I have been waiting for sometime for this can you please provide some update

haseeb-dc avatar May 11 '23 12:05 haseeb-dc