I have simple Vue project on newest Vue CLI 3 (I'm newbie on both). In src I have jpg / png images in 100% quality. By default cli while build will make dist directory with my images adding hash (image.jpg to image.7a97ca45.jpg) but without any compression.
So I have added imagemin-webpack-plugin and imagemin-mozjpeg and imagemin-pngquant to get optimization. And it works. In dist now I have much smaller jgp's and png's.
const ImageminPlugin = require('imagemin-webpack-plugin').default
const ImageminMozjpeg = require('imagemin-mozjpeg')
const ImageminPngquant = require('imagemin-pngquant')
module.exports = {
configureWebpack: {
plugins: [
new ImageminPlugin({
plugins: [
ImageminMozjpeg({
quality: 70
}),
ImageminPngquant({
quality: '80-90'
})
]
})
]
}
}
But now I want to have also .webp images created from original jpg's. So i should get for example both image.7a97ca45.jpg and image.7a97ca45.jpg.webp (or image.7a97ca45.webp) so then I can detect browser and serve correct format.
But I do not understand how I can force webpack in vue.config.js to create these files. I tried for example imagemin-webp-webpack-plugin but this does nothing ("imagemin-webp-webpack-plugin: 0 MB saved - in console"). I also tried to add imagemin-webp to imageminplugin config but this also don't work because I do not have original webp in my source, just want to convert new one.
All topics I could find about webp was for normal webpack or older vue-cli, and best I achieved was copying whole images directory with optimization or created webp images from already compressed jpg's (not originals). But i want to keep normal loader with all hashing etc. What's best approach to this?