tschaub / grunt-newer

Configure Grunt tasks to run with newer files only.
https://npmjs.org/package/grunt-newer
MIT License
945 stars 53 forks source link

Possible to combine with tasks lazy loading? #25

Closed lmartins closed 10 years ago

lmartins commented 10 years ago

Hi,

I've been using grunt-newer pretty much everywhere but recently had the need to add an extra layer to my gruntfiles as they were becoming pretty slow at times.

Im now using jit-grunt to load the tasks only as needed but this had an undesired side effect, grunt-newer now seems to do nothing, on every change all files get processed as if they were all newer.

This is most likely due to any misstep on my configuration, so I was wondering if you can help me identify where the problem is.

I've also noticed that the cache files are all zero bytes, perhaps the reason the process happens for every file everytime.

I've simplified my Gruntfile a bit to show how I am trying to use grunt-newer:

'use strict';

module.exports = function ( grunt ) {

  require('time-grunt')(grunt);
  require('jit-grunt')(grunt, {
    "assemble": "assemble",
    "newer"   : "grunt-newer",
    "sass"    : "grunt-sass",
    "watch"   : "grunt-contrib-watch",
    "tinypng" : "grunt-tinypng"
  });

  // set up grunt
  grunt.initConfig({

    pkg: grunt.file.readJSON('package.json'),

    watch: {
      assemble: {
        files: ['{pages,templates}/{,*/}*.{md,hbs,yml}'],
        tasks: ['assemble'],
        options: {
          livereload: false
        }
      },
      images: {
        files: ['images/{,*/}*.png'],
        tasks: ['newer:tinypng'],
        options: {
          livereload: false
        }
      },
      livereload: {
        options: {
          livereload: true
        },
        files: [
          '<%= config.dist %>/{,*/}*.html',
          '<%= config.dist %>/css/{,*/}*.css',
          '<%= config.dist %>/js/*.min.js',
          '<%= config.dist %>/images/{,*/}*.{png,jpg,jpeg}'
        ]
      }
    },

    assemble: {

      options: {
        flatten: false,
        assets: '<%= config.dist %>',
        dist: '<%= config.dist %>',
        layout: 'templates/layouts/default.hbs',
        partials: 'templates/partials/*.hbs',
      },

      pages: {
        files: { '<%= config.dist %>': ['pages/{,*/}*.hbs'] }
      }

    },

    tinypng: {
      options: {
        apiKey: "####"
      },
      compress: {
        expand: true,
        src: 'images/*.png',
        dest: 'dist/'
      }
    }

  });

  grunt.registerTask('default', [
    'connect',
    'watch'
  ]);

};

With this setup, when I change an image for example, i get the following output: screenshot 2013-12-27 10 33 50

lmartins commented 10 years ago

Btw, if I run the task manually (outside of the watcher) but still lazy-loading the plugin, I get the correct behaviour: screenshot 2013-12-27 10 52 19

lmartins commented 10 years ago

Didn't worked before, it does now. Not sure what changed. Closing now.

tschaub commented 10 years ago

Thanks for the report. Please reopen if you notice odd behavior again.