Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot override the default minimizerOptions.plugins, I can only add new plugins #30

Open
FreekVR opened this issue Apr 15, 2021 · 1 comment

Comments

@FreekVR
Copy link

FreekVR commented Apr 15, 2021

I was trying to override the default plugins in my project like so from nuxt.config.js;

[...]
imagemin: {
  mimizerOptions: {
    plugins: [
      [ 'gifsicle', { interlaced: false} ],
      [ 'jpegtran', { progressive: false} ],
      [ 'optipng', { optimizationLevel: 9 } ],
    ]
  }
}

However, I was having issues with these changes not applying and it appears to be the case that custom imagemin plugins are getting pushed to the defaults, instead of overriding them. I was able to verify this by adding the following debug code in dist/module.js line 103 (right after defining the options)

const util = require('util')
console.log(util.inspect(options, false, null, true /* enable colors */))

Given the config from my project, this debug code outputs the following;

  minimizerOptions: {
    plugins: [
      [ 'gifsicle', { interlaced: true } ],
      [ 'jpegtran', { progressive: true } ],
      [ 'optipng', { optimizationLevel: 5 } ],
      [
        'svgo',
        { plugins: [ { removeViewBox: false } ] }
      ],
      [ 'gifsicle', { interlaced: false} ],
      [ 'jpegtran', { progressive: false} ],
      [ 'optipng', { optimizationLevel: 9 } ],

I would expect that I would be able to override or remove the default plugins and their options, but as it stands, it only appears I can add new ones? Or if I'm missing something here please let me know where I went wrong :)

@tex0l
Copy link

tex0l commented Jul 26, 2021

Hi,
There is a way to trick it, use a function:

[...]
imagemin: {
  mimizerOptions: {
    plugins: () => [
      [ 'gifsicle', { interlaced: false} ],
      [ 'jpegtran', { progressive: false} ],
      [ 'optipng', { optimizationLevel: 9 } ],
    ]
  }
}

Otherwise it just concatenates arrays.

This should be documented, but it's the default behaviour of https://github.com/unjs/defu which is used to merge configs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants