4

I have more than 100 images in my images/ folder.

Here is my imagemin - Grunt Config

// The following *-min tasks produce minified files in the dist folder
imagemin: {
  dist: {
    files: [{
      expand: true,
      cwd: '<%= config.app %>/images',
      src: '{,*/*/}*.{gif,jpeg,jpg,png,ico}',
      dest: '<%= config.dist %>/images'
    }]
  }
}

When I run grunt build I saw this

Running "imagemin:dist" (imagemin) task
Minified 7 images (saved 492.79 kB)

Only 7 of my images got minified. Not all. I've tried changing the * around in a diff combination, but so far - no luck.


src: '{,*/*/}*.{gif,jpeg,jpg,png,ico}'

How do I fix my src to minified everything in my images folder ?

Community
  • 1
  • 1
code-8
  • 54,650
  • 106
  • 352
  • 604

1 Answers1

2

I think the problem might be in the src globbing pattern. The pattern you are using only matches those images that are in the cwd root or in a two levels deep ones ({,*/*/}).

If you want all the images in the cwd directory to be minified regardless the levels of subdirectories they reside, you should use the **/* globbing pattern instead:

imagemin: {
  dist: {
    files: [{
      expand: true,
      cwd: '<%= config.app %>/images',
      src: '**/*.{gif,jpeg,jpg,png,ico}',
      dest: '<%= config.dist %>/images'
    }]
  }
}
dreyescat
  • 13,558
  • 5
  • 50
  • 38
  • Thank-you very much. I'm trying your code right now. – code-8 Jun 02 '15 at 20:02
  • I got this error `"Warning: Running "imagemin:dist" (imagemin) task Warning: Error: Command failed: /Users/bunlong/Desktop/yeoman project/yo/node_modules/grunt-contrib-imagemin/node_modules/imagemin/node_modules/imagemin-optipng/node_modules/optipng-bin/vendor/optipng -strip all -quiet -clobber -o 3 -out /var/folders/54/y_678c6n7q7_pgk1v5lkzwnr0000gp/T/4a47ee72-0c86-4ef8-bf37-876b37850777 /var/folders/54/y_678c6n7q7_pgk1v5lkzwnr0000gp/T/df5a73eb-8d62-431d-926f-7a1e9f5b9084 in file app/images/overlays/02.png Use --force to continue. Aborted due to warnings."` – code-8 Jun 02 '15 at 20:06
  • It seems to be a problem with the `optipng` command. There is an open issue in the grunt-contrib-imagemin repo that describes the same behavior https://github.com/gruntjs/grunt-contrib-imagemin/issues/290. Someone proposes updating imagemin to latest version but... not sure if it really solves the issue. – dreyescat Jun 02 '15 at 21:57