简体   繁体   中英

Why is grunt-contrib-imagemin not using the option I set?

I have imagemin working through grunt.

As show below in the Gruntfile, I have things like optimisationLevel: 7 and so on.

The use: command tells it to use a different algo for compressing the images. It listens to all of my options except for the use one.

Anyone know why this is? Am I doing something wrong syntax wise?

Gruntfile:

module.exports = function(grunt) {
  var mozjpeg = require('imagemin-mozjpeg');

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
     imagemin: {
        dynamic: {                       // Task                        // Target
          options: {
            optimizationLevel: 7,
            progressive: false,
            svgoPlugins: [{ removeViewBox: false }],
            use: [mozjpeg({fastcrush: true})]
          },
          files: [{
            expand: true,                  // Enable dynamic expansion
            cwd: 'src/',                   // Src matches are relative to this path
            src: ['**/*.{png,jpg,gif}'],   // Actual patterns to match
            dest: 'build/img'                  // Destination path prefix
          }]
        }
      }
  });

  // Load the plugins
  //grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-imagemin');
  // Default tasks
  grunt.registerTask('default', ['imagemin']);



};

CLI - You can see on line 40 it says use null.

It seems to be a logging issue of the grunt.verbose.writeFlags function which grunt use to log the task options in verbose mode.
If you will add the following code to you gruntfile.js, you will notice it incorrectly logs the value of 'use' as null:

grunt.verbose.writeflags({use: [mozjpeg()]}, 'Test');

The cause might be this reported issue , although it is not exactly the same case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM