Greg
Greg

Reputation: 3568

Grunt seems to skip some tasks on first run

Please forgive my grunt noobiness. I have grunt 0.4 installed correctly and working, and I'm loving it.

I cannot understand however, why my default task always skips some sub-tasks, on the first time.

Here's the relevant part of Gruntfile:

// Project configuration.
grunt.initConfig({
  pkg: grunt.file.readJSON('package.json'),

  copy: {
    main: {
      files: [
        {src: ['src/**'], dest: 'temp/'} // includes files in path and its subdirs
      ]
    }
  },

  uglify: {
    main: {
      files: grunt.file.expandMapping(['temp/**/*.js', '!temp/**/*min.js'], './')
    }
  },

  imagemin: {
    main: {
      files: grunt.file.expandMapping(['temp/**/*.png', 'temp/**/*.jpg'], './')
    }
  },

  compress: {
    main: {
      options: {
        archive: 'archive.zip'
      },
      files: [
        {expand: true, cwd: 'temp/src/', src: ['**'], dest: './'} // makes all src relative to cwd
      ]
    }
  },

  clean: ["temp", "archive.zip"]

});

// Load the plugins
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-clean');

// Default task(s).
grunt.registerTask('default', ['clean', 'copy', 'uglify', 'imagemin', 'compress']);
grunt.registerTask('test', ['clean', 'copy', 'uglify']);

On the first run of grunt, both uglify and imagemin tasks do not process (and output) anything. If I launch it again it all works fine. If I manually delete the "temp" folder and relauch grunt, uglify and imagemin do not do anything again.

Please help me finding what I am doing wrong. Node is version 0.8.2, gruntcli 0.1.6, grunt 0.4.0

Thanks for reading

Upvotes: 2

Views: 765

Answers (1)

hereandnow78
hereandnow78

Reputation: 14434

the reason for that, is that grunt.file.expandMapping (which you use in both tasks) is running when the gruntfile is loaded and NOT when the actual task is run. so files which are generated through other tasks will not be availableto your imagemin/uglify-task.

you should use the files-object the same-way you do in your other tasks!

Upvotes: 1

Related Questions