簡體   English   中英

grunt imagemin不會移動未優化的圖像

[英]grunt imagemin doesn't move unoptimized images

我剛剛在我正在從事的項目中注意到了這一點:

說您有大量要壓縮的圖像,它們位於images-src文件夾中。 壓縮后,它們進入images文件夾,這就是您在項目中使用的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?

您可以在將目標文件中所有未優化的圖像移動之后立即執行復制任務。

使用一些過濾器以避免覆蓋目標中已存在的壓縮圖像。

 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));
    },
 },
},

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM