I'd suggest enhancing Atillas solution. Rebuilding all templates on every change isn't optimal and will piss you off on large projects.
Here's what should help:
Use newer plugin to process only changed files
Install: npm install grunt-newer --save-dev
Docs: https://www.npmjs.org/package/grunt-newer#optionsoverride
Usage:
- prefix tasks with newer:
- add grunt.loadNpmTasks('grunt-newer'); to gruntfile
- use override option to check includes (the magic you're looking for)
newer: {
options: {
override: function (detail, include) {
if (detail.task === 'jade') {
checkForModifiedImports(detail.path, detail.time, include);
} else {
include(false);
}
}
}
}
Use watch to detect file changes
Install: npm install grunt-contrib-watch --save-dev
Docs: https://www.npmjs.org/package/grunt-contrib-watch
Usage:
- add grunt.loadNpmTasks('grunt-contrib-watch'); to gruntfile
- task can look like something like this
watch: {
scripts: {
files: '**/*.jade',
tasks: ['newer:jade'],
options: {
interrupt: true
},
},
}