2014-12-02 59 views
1

我无法使用grunt-contrib-imagemin,因为我无法得到它压缩任何图像。没有图像被压缩使用grunt-contrib-imagemin

这里是我的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']); 

} 

当我在命令行中运行的呼噜声,每个CONCAT和cssmin运行良好,而imagemin - 尽管运行没有错误 - 返回以下消息。

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

有关信息,我的文件夹结构如下。

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

image文件夹目前包含7个PNG和2个JPG文件,但我无法弄清楚为什么它没有对它们做任何事情。

任何帮助非常感谢。

感谢

回答

0

src -Properties在CONCATcssmin任务不包含if3。你的imagemin配置。删除,应该可能有帮助...

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

这是我的想法也一样,但删除的结果在下面的错误。 '正在运行'imagemin:动态“(imagemin)任务' '致命错误:无法读取未定义的属性'内容' – rnnbrwn 2014-12-02 16:01:56

+0

这似乎发生[这里](https://github.com/gruntjs/grunt-contrib -imagemin/blob/master/tasks/imagemin.js#L57)这可能意味着你的某些图像已损坏。这也意味着,我发布的配置是正确的,因为imagemin似乎运行。用--verbose标志运行你的咕噜任务以获取更多信息! – hereandnow78 2014-12-02 16:09:40

+0

从bbc.co.uk中下载了一些我的图片,结果相同。这里是'grunt imagemin --verbose'的输出> – rnnbrwn 2014-12-02 16:33:44