0

I've just noticed this on a project I'm working on:

say you have tons of images to compress and they sit in an images-src folder. once compressed, they go in an images folder and these are the ones you use in your project.

it can happen that some images don't need any optimization and I've noticed they stay in the source folder and don't move in images but that poses a problem because now, some images are missing and I don't even know exactly which ones.

is this a bug or am i missing something?

my configuration is pretty straight forward:

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

how do i move my unoptimized images from source to dist anyway?

4

1 回答 1

0

您可以在移动目标中所有未优化的图像之后执行复制任务。

使用一些过滤器来避免覆盖已经在 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));
    },
 },
},
于 2016-04-12T15:09:40.707 回答