gruntjs/grunt-contrib-livereload — pull request #31 by ataube (2013-03-18 16:33:47+00:00)
Title: Public access to livereload script tag snippet

Hey there,

it would be nice to reuse the livereload script tag snippet (see PR), to extend for instance the connect middleware with some custom functionality. In my case I would like to plugin a dispatcher for app routes to be served with my index.html:

var lrScriptTag = require('grunt-contrib-livereload/lib/utils').livereloadScriptTag;

middleware: function (connect, options) {
var dispatch = require('dispatch');
var routeDispatcher = function(req, res, next) {

var index = grunt.file.read(yeomanConfig.app + '/index.html');
index = index.replace(/<\/body>/, function (w) {
return lrScriptTag() + w;
});
res.write(index);
res.end();
}
return [
lrSnippet,
mountFolder(connect, '.tmp'),
mountFolder(connect, yeomanConfig.app),
dispatch({
'/([\\w\\/]+)': routeDispatcher
})
];
}

Or do you have any better solutions to solve my use case? thanks