简体   繁体   中英

No images being compressed using grunt-contrib-imagemin

I'm having trouble using grunt-contrib-imagemin, insofar as I can't get it to compress any images.

Here's my Gruntfile.js

module.exports = function(grunt) {

    // 1. All configuration goes here 
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        concat: {   
            dist: {
                src: [
                    'css/{base,global,medium,large}.css', // All CSS in the CSS folder
                ],
                dest: 'css/build/production.css',
            }
        },

        cssmin: {
            build: {
                src: 'css/build/production.css',
                dest: 'css/build/production.min.css'
            }
        },

        imagemin: {
            dynamic: {
                files: [{
                    expand: true,
                    cwd: 'if3/images',
                    src: ['**/*.{png,jpg,gif}'],
                    dest: 'images/build'
                }]
            }
        }       

    });

    // 3. Where we tell Grunt we plan to use this plug-in.
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-cssmin'); 
    grunt.loadNpmTasks('grunt-contrib-imagemin');

    // 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
    grunt.registerTask('default', ['concat', 'cssmin', 'imagemin']);

}

When I run grunt from the command line, each of concat and cssmin run fine, whereas imagemin - although running without errors - returns the following message.

Running "imagemin:dynamic" (imagemin) task
Minified 0 images (saved 0 B)

For info, my folder structure is as follows.

if3\
  css\
    *.css
  images\
    *.png
    *.jpg
  js\
    *.js
  node_modules\
    etc.
  Gruntfile.js
  package.json
  *.html

The image folder currently contains 7 PNG and 2 JPG files, but I can't figure out why it's not doing anything with them.

Any help much appreciated.

Thanks

your src -properties in your concat and cssmin tasks do not contain if3 . your imagemin config does. removing that should probably help...

imagemin: {
    dynamic: {
        files: [{
            expand: true,
            cwd: 'images',
            src: ['**/*.{png,jpg,gif}'],
            dest: 'images/build'
        }]
    }
}   

you don't need use: dynamic {} or static {} and will works perfect.

see: Grunt imagemin running but not minifying

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