R
R
Richard-082020-10-07 14:47:10
HTML
Richard-08, 2020-10-07 14:47:10

Using images in WEBP format, using webpack plugin?

Is it possible to intervene in html through the plugin, find all , convert images from them to webp and replace them with a tag for compatibility?

There is such a solution using the imagemin and imagemin-webp plugins. That is, the plugin converts those in the images folder into the webp format. With this, everything is clear.
5f7da6c6cd9de734983562.png
Then we use the string-replace-webpack-plugin to change the tags. 5f7da78ce510e749467556.png
And this approach only works when we specify the path of the images in the component statically, i.e. , and we get in the output<img src="../assets/images/1.jpg" alt="">

<picture>
  <source srcet='../assets/images/1.webp'>
  <img src="../assets/images/1.jpg" alt="">
</picture>

But it will not work to change dynamic images like this, for example
<img :src="myImg" alt="">
import myImg from '../assets/img/1.jpg'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RokeAlvo, 2020-10-15
@RokeAlvo

doesn't form webp or change the markup?
but in general it is easier to solve the webp problem on nginx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question