Grunt如何只调整最后添加的图像?

时间:2017-08-31 09:04:36

标签: automation gruntjs frontend

这是我的咕噜文件:

module.exports = function(grunt) {

  grunt.initConfig({
    responsive_images: {
      dev: {
        options: {
                  sizes: [{
                    name: 'small',
                    width: '30%',
                    quality: 30
                  },{
                    name: 'medium',
                    width: '50%',
                    quality: 50
                  },{
                    name: 'large',
                    width: '60%',
                    quality: 60
                  },{
                    name: 'compressed',
                    width: '100%',
                    quality: 50
                  }]
        },
        files: [{
          expand: true,
          src: ['img/*.{gif,jpg,png}'],
          cwd: 'Sito/',
          dest: 'Sito/'
        }]
      }
    },
   watch: {
            scripts: {
                files: ['**/*.{gif,jpg,png}'],
                tasks: ['responsive_images'],
                options: {
                    spawn: false,
                    event: ['changed']
                },
            } 
        }
  });

 grunt.loadNpmTasks('grunt-responsive-images');
 grunt.loadNpmTasks('grunt-contrib-watch');
 grunt.registerTask('default', ['responsive_images']);
 };

我只想调整文件夹中添加的最后一张图片,我该怎么做? 现在,当我添加图像时,所有以前的图像都是用响应图像编辑的。

谢谢你,如果你想回答我的话! =)

1 个答案:

答案 0 :(得分:0)

解决方案是:

module.exports = function(grunt) {

  grunt.initConfig({
    responsive_images: {
      dev: {
        options: {
                  newFilesOnly: 'true',
                  sizes: [{
                    name: 'small',
                    width: '30%',
                    quality: 30
                  },{
                    name: 'medium',
                    width: '50%',
                    quality: 50
                  },{
                    name: 'large',
                    width: '60%',
                    quality: 60
                  },{
                    name: 'compressed',
                    width: '100%',
                    quality: 50
                  }],
        },
        files: [{
          expand: true,
          src: ['img/*.{gif,jpg,png}'],
          cwd: 'Sito/',
          dest: 'Sito/img-resp/'
        }]
      }
    },
   watch: {
            scripts: {
                files: ['**/*.{gif,jpg,png}'],
                tasks: ['responsive_images'],
                options: {
                    spawn: false,
                    event: ['added']
                },
            } 
        }
  });

  grunt.loadNpmTasks('grunt-responsive-images');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.registerTask('default', ['responsive_images']);
};