用grunt观察并重新编译单个模板

我有一堆玉模板的目录,还有一个将所有这些编译成单独的html文件的咕 task任务。

我希望有一个监视任务 ,当它改变时重新编译一个模板,但是现在我的任务在任何模板发生改变时重新编译每个模板。

这是一个要点的演示 。

有没有一种简洁的方式来编写一个任务,当它改变时重新编译一个模板,但不是所有的其他模板?

解决的办法是在文件列表中添加一个filter函数:

 var fs = require('fs'); var join = require('path').join; module.exports = function(grunt) { grunt.initConfig({ jade: { files: { src: ['*.jade'], dest: './', expand: true, ext: '.html', filter: function(destDir, src) { var dest = join(destDir, src.replace(/jade$/, 'html')); var destMod; try { destMod = +fs.lstatSync(dest).mtime; } catch (e) { if (e.code === 'ENOENT') { // there's no html file, so ensure that the // jade file is compiled by returning true return true; } throw e; } return fs.lstatSync(src).mtime > destMod; } } }, watch: { files: ['*.jade'], tasks: ['jade'] } }); grunt.loadNpmTasks('grunt-contrib-jade'); grunt.loadNpmTasks('grunt-contrib-watch'); };