Question

I want to watch my coffee and grunt files at the same time. When I just watch coffee files there is no problem but when I add a jade watcher to my file the watcher only compiles once and eventhough there is an update, watcher is not compiling those new updates.

Any help is kindly appreciated:

Here is when there is just coffee watcher in my system:

Compiles whenever there is an update at a coffee file: Gruntfile.coffee

module.exports = (grunt) ->

  grunt.initConfig
    pkg         : grunt.file.readJSON "package.json"

    coffee      :
      compile   :
        options : sourceMap: on
        files   :
          ['dist/client/js/main.js': 'client/app/scripts/app.coffee',
          'server.js': 'server.coffee']

    watch       :
      coffee    :
        options : atBegin: yes
        files   : [ 'client/scripts/*.coffee',
                    'client/scripts/controllers/*.coffee',
                    'server.coffee']
        tasks   : ['coffee', 'jade']


  grunt.loadNpmTasks 'grunt-contrib-coffee'
  grunt.loadNpmTasks 'grunt-contrib-watch'

  grunt.registerTask 'default', ['watch']

The question is, why does the watcher functions just at startup but not anymore?

Compiles just at startup: Gruntfile.coffee

module.exports = (grunt) ->

  grunt.initConfig
    pkg         : grunt.file.readJSON "package.json"

    coffee      :
      compile   :
        options : sourceMap: on
        files   :
          ['dist/client/js/main.js': 'client/app/scripts/app.coffee',
          'server.js': 'server.coffee']

    jade: 
      compile: 
        options: 
          data: 
            debug: false
        files: 
          ['dist/client/index.html': ['client/app/views/index.jade'] ]

    watch       :
      coffee    :
        options : atBegin: yes
        files   : [ 'client/scripts/*.coffee',
                    'client/scripts/controllers/*.coffee',
                    'server.coffee']
        tasks   : ['coffee', 'jade']


  grunt.loadNpmTasks 'grunt-contrib-coffee'
  grunt.loadNpmTasks 'grunt-contrib-jade'
  grunt.loadNpmTasks 'grunt-contrib-watch'


  grunt.registerTask 'default', ['watch']

Here is my console log out for the command: grunt --verbose

Initializing
Command-line options: --verbose

Reading "Gruntfile.coffee" Gruntfile...OK

Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK

Registering "grunt-contrib-coffee" local Npm module tasks.
Reading /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-coffee/package.json...OK
Parsing /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-coffee/package.json...OK
Loading "coffee.js" tasks...OK
+ coffee

Registering "grunt-contrib-jade" local Npm module tasks.
Reading /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-jade/package.json...OK
Parsing /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-jade/package.json...OK
Loading "jade.js" tasks...OK
+ jade

Registering "grunt-contrib-watch" local Npm module tasks.
Reading /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-watch/package.json...OK
Parsing /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-watch/package.json...OK
Loading "watch.js" tasks...OK
+ watch
Loading "Gruntfile.coffee" tasks...OK
+ default

No tasks specified, running default tasks.
Running tasks: default

Running "default" task

Running "watch" task
Waiting...Verifying property watch exists in config...OK
Verifying property watch.coffee.files exists in config...OK
Watching server.coffee for changes.
Watching .git for changes.
Watching .idea for changes.
Watching bower_components for changes.
Watching client for changes.
Watching dist for changes.
Watching node_modules for changes.
Watching server for changes.
OK

Initializing
Command-line options: --verbose

Reading "Gruntfile.coffee" Gruntfile...OK

Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK

Registering "grunt-contrib-coffee" local Npm module tasks.
Reading /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-coffee/package.json...OK
Parsing /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-coffee/package.json...OK
Loading "coffee.js" tasks...OK
+ coffee

Registering "grunt-contrib-jade" local Npm module tasks.
Reading /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-jade/package.json...OK
Parsing /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-jade/package.json...OK
Loading "jade.js" tasks...OK
+ jade

Registering "grunt-contrib-watch" local Npm module tasks.
Reading /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-watch/package.json...OK
Parsing /Users/neva/Documents/projects/sdn-monitor/node_modules/grunt-contrib-watch/package.json...OK
Loading "watch.js" tasks...OK
+ watch
Loading "Gruntfile.coffee" tasks...OK
+ default

Running tasks: coffee, jade

Running "coffee" task

Running "coffee:compile" (coffee) task
Verifying property coffee.compile exists in config...OK
Files: client/app/scripts/app.coffee -> dist/client/js/main.js
Files: server.coffee -> server.js
Options: bare=false, join=false, sourceMap, separator="\n"
Reading client/app/scripts/app.coffee...OK
Writing dist/client/js/main.js...OK
File dist/client/js/main.js created.
Writing dist/client/js/main.js.map...OK
File dist/client/js/main.js.map created (source map).
Reading server.coffee...OK
Writing server.js...OK
File server.js created.
Writing ./server.js.map...OK
File ./server.js.map created (source map).

Running "jade" task

Running "jade:compile" (jade) task
Verifying property jade.compile exists in config...OK
Files: client/app/views/index.jade -> dist/client/index.html
Options: namespace="JST", separator="\n\n", amd=false, data={"debug":false}
Reading client/app/views/index.jade...OK
Writing dist/client/index.html...OK
File "dist/client/index.html" created.

Done, without errors.
Completed in 0.731s at Wed Jan 22 2014 16:50:44 GMT+0200 (EET) - Waiting...
Was it helpful?

Solution

You told watch to watch for changes in coffee and jade but only included coffee files in the files array, I think you need to add the jade file to be watched in there too

watch       :
  coffee    :
    options : atBegin: yes
    files   : [ 'client/scripts/*.coffee',
                'client/scripts/controllers/*.coffee',
                'server.coffee', 'client/app/views/index.jade'] // add the jade file here
    tasks   : ['coffee', 'jade']

Update

watch:
  coffee:
    files: ["client/scripts/*.coffee", "client/scripts/controllers/*.coffee", "server.coffee", "client/app/views/index.jade"]
    tasks: ["coffee"]

  jade:
    files: ["client/app/views/index.jade"]
    tasks: ["jade"]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top