8

I am new to gruntjs and here is my simple gruntfile:

/* global module:false */
module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    watch: {
      tasks: 'coffee'
    },
    coffee: {
      compile: {
        files: {
          'js/javascript/*.js': ['js/coffeescript/*.coffee'] // 1:1 compile
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-coffee');

  // Default task.
  grunt.registerTask('default', 'coffee');
};

When I run grunt it compiles fine. However, when I run grunt watch, it's just waiting and not detecting my changes.

ontk
  • 942
  • 1
  • 10
  • 24

1 Answers1

12

You should add files to watch:

watch: {
  coffee: {
    files: ['js/coffeescript/*.coffee'],
    tasks: 'coffee'
  }
}

From example

Kyle Robinson Young
  • 13,732
  • 1
  • 47
  • 38
Ivan Dyachenko
  • 1,348
  • 9
  • 16
  • That worked. Thank you. One more question, what is the syntax for preserving the folder structure of the coffee folder in the compiled js folder without having to list all of the coffeescript folders of your app? – ontk Oct 10 '12 at 17:34
  • It can be done with the unstable alpha version of Grunt, v0.4a but it is still being discussed. Check out this thread: https://github.com/gruntjs/grunt-contrib-coffee/pull/1 – Kyle Robinson Young Oct 10 '12 at 18:39