javascript - Watch and recompile individual templates with grunt -
i have directory bunch of jade templates, , grunt task compiles of them individual html files.
i'd have watch task recompiles template when changes, right task recompiles every template when of them change.
here demo in gist.
is there succinct way write task recompiles template when changes, not of other templates?
the solution add filter
function files list:
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, ensure // jade file compiled 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'); };
Comments
Post a Comment