简体   繁体   English

grunt imagemin不会移动未优化的图像

[英]grunt imagemin doesn't move unoptimized images

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. 说您有大量要压缩的图像,它们位于images-src文件夹中。 once compressed, they go in an images folder and these are the ones you use in your project. 压缩后,它们进入images文件夹,这就是您在项目中使用的images文件夹。

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. 可能会发生某些图像不需要任何优化的情况,我注意到它们保留在源文件夹中并且不会在images移动,但是这带来了问题,因为现在某些图像丢失了,我什至不知道哪个。

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? 无论如何,我如何将未优化的图像从源移动到dist?

you can do a copy task just after to move all the unoptimized image in your dest. 您可以在将目标文件中所有未优化的图像移动之后立即执行复制任务。

With some filter to avoid to overwrite the compressed images who are already in the 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));
    },
 },
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM