My project has over 300 CoffeeScript files, so it takes several seconds to recompile everything. I'd like to only recompile the changed CoffeeScript files.
Here's the closest I've come so far, but the "frontend-src/coffeescript" folder structure is being copied from the src directory to the dest directory.
coffee: {
changed: {
expand: true,
cwd: './',
src: ['<%= grunt.regarde.changed %>'],
dest: 'public/js/',
ext: '.js'
}
},
regarde: {
coffee: {
files: 'frontend-src/coffeescript/**/*.coffee',
tasks: ['coffee:changed', 'livereload']
}
}
This is all with Grunt 0.4.0. Any help would be greatly appreciated!
I've had the same issue. I solved it using the
regarde:file
event.First I listen for changed files by using the
regarde:file
event. This will feed the configuration for two tasks:clean:coffee
if files in the source location has been deleted andcoffee:refresh
if files have been changed/added.Then the
regarde
task will trigger its tasks, which will launchrefresh:coffee
(not to be mistaken fromcoffee:refresh
). This task will check if there is configuration added forclean:coffee
and/or forcoffee:refresh
and run these tasks if needed (via functiongrunt.task.run
). If will also reset the flag, which will cause the next receivedregarde:file
event to cleanup the configuration again.In depth explanation:
First of all,
regarde
config:Then I listen for the
regarde:file
event, where I update theclean:coffee
andcoffee:refresh
file lists in their config.Feed the configuration based on the
regarde:file
event:It is easy to update configuration via
grunt.config()
function. Below the code snippets to feedcoffee:refresh
andclean:coffee
.Adding config to
coffee:refresh
:Adding config to
clean:coffee
:Task
refresh:coffee
gets triggered:grunt.regarde.changed
is an array correct?Should
src: ['<%= grunt.regarde.changed %>']
be
src: '<%= grunt.regarde.changed %>'
I looked through grunt-contrib-coffee's source for a second to see if it could be not correctly handling whatever you're giving it. Looked kind of likely that the stringified array you're giving it, doesn't get caught and dealt with.
I think what you're passing accidentally may be:
src: [ '[path1, path2, path3, etc]' ]
If I'm way off base, leave a comment and I'll delete this answer.
I had this issue myself and I was able to come up with a solution for it inspired by the comments on this issue: https://github.com/gruntjs/grunt-contrib-watch/issues/14
It is actually for the grunt-contrib-watch plugin, but it should also work for grunt-regarde, as it has similar events.
The idea is to bind a callback the
watch
event, in which you add a new task to the grunt configuration with the changed file's path, then run it.From my
Gruntfile.coffee
:The nospawn is important for the watch task, so it runs the new task before the livereload task. I am pretty sure regarde does not spawn child processes by default.