2016-04-12 19 views
0

我剛剛注意到這一個項目我工作:咕嚕imagemin不動未優化的圖像

說你有噸圖像的壓縮和他們坐在一個images-src文件夾中。一旦壓縮,他們將進入images文件夾,這些是您在項目中使用的文件夾。

它可能發生,有些圖像不需要任何優化,我注意到他們留在源文件夾中,不要在images移動,但這會帶來問題,因爲現在,一些圖像丟失,甚至不知道哪一個。

這是一個錯誤還是我錯過了什麼?

我的配置是非常簡單的:

imagemin: { 
    dynamic: { 
     files: [{ 
      expand: true, // Enable dynamic expansion 
      cwd: '_src/images/', // source images (not compressed) 
      src: ['**/*.{png,jpg,gif,svg}'], // Actual patterns to match 
      dest: '_dev/images/' // Destination of compressed files 
     }] 
    } 
}, //end imagemin 

我如何從源移動我沒有優化的圖像反正DIST?

回答

0

你可以在你的dest中移動所有未優化的圖像之後立即執行復制任務。

使用一些過濾器來避免覆蓋已經在dest中的壓縮圖像。

copy: { 
    unoptimizedImage: { 
    expand: true, 
    cwd: '_src/images/', 
    src: ['**/*.{png,jpg,gif,svg}'], 
    dest: '_dev/images/' 

    // Copy if file does not exist. 
    filter: function (filepath) { 
     // NPM load file path module. 
     var path = require('path'); 

     // Construct the destination file path. 
     var dest = path.join(
      grunt.config('copy.main.dest'), 
      path.basename(filepath) 
     ); 

     // Return false if the file exists. 
     return !(grunt.file.exists(dest)); 
    }, 
}, 
},