Thursday, 19 September 2013

Grunt watch: compile only one file not all

Grunt watch: compile only one file not all

I have grunt setup to compile all of my coffee files into javascript and
maintain all folder structures using dynamic_mappings which works great.
coffee: {
dynamic_mappings: {
files: [{
expand: true,
cwd: 'assets/scripts/src/',
src: '**/*.coffee',
dest: 'assets/scripts/dest/',
ext: '.js'
}]
}
}
What I would like to do is then use watch to compile any changed coffee
file and still maintain folder structure. This works using the above task
with this watch task:
watch: {
coffeescript: {
files: 'assets/scripts/src/**/*.coffee',
tasks: ['coffee:dynamic_mappings']
}
}
The problem is that when one file changes it compiles the entire directory
of coffee into Javascript again, it would be great if it would only
compile the single coffee file that was changed into Javascript. Is this
naturally possible in Grunt or is this a custom feature.
We have custom watch scripts at work and I'm trying to sell them on Grunt
but will need this feature to do it.

No comments:

Post a Comment