nuxt-community / imagemin-module

Automatically optimize (compress) all images used in Nuxt.js
MIT License
50 stars 1 forks source link

Use imagemin-webp #21

Closed mickaelchanrion closed 3 years ago

mickaelchanrion commented 4 years ago

Hey, I'm trying to use imagemin-webp to transform all my images in webp format.

By using this config in nuxt.config.js

imagemin: {
  enableInDev: true, // debuging
  imageminOptions: {
    plugins: [
      ['gifsicle', { interlaced: true }],
      ['jpegtran', { progressive: true }],
      ['optipng', { optimizationLevel: 5 }],
      ['svgo', { plugins: [{ removeViewBox: false }] }],
      ['webp', { resize: { width: 1280, height: 800 } }],
    ],
  },
},

I get my images resized to 1280*800 but the image keeps its extension. How can I fix that? 🤔

Thanks for your help

atinux commented 3 years ago

Hi @mickaelchanrion

Could you create a reproduction on CodeSandBox?

ricardogobbosouza commented 3 years ago

Hi @mickaelchanrion Sorry for delay response

You can configure it like this:

export default {
  buildModules: [

    // gif,jpb,png,svg
    ['@nuxtjs/imagemin', {
      imageminOptions: {
        plugins: [
          ['gifsicle', { interlaced: true }],
          ['jpegtran', { progressive: true }],
          ['optipng', { optimizationLevel: 5 }],
          ['svgo', { plugins: [{ removeViewBox: false }] }]
        ]
      }
    }],

    // webp
    // https://www.npmjs.com/package/imagemin-webpack#name
    ['@nuxtjs/imagemin', {
      imageminOptions: {
        name: '[path][name].webp',
        plugins: [
          ['webp', { resize: { width: 1280, height: 800 } }]
        ]
      }
    }]
  ]
}