grunt-express
grunt-express copied to clipboard
livereload option doesn't inject livereload script for static files
It is not injecting the livereload script into files that are listed in the bases option. When I use grunt-contrib-connect with connect-livereload and use the livereload middleware in connect options, the static files do get the livereload script injected successfully.
Alternatively, I tried to set middleware option in grunt-express, but it gives me the error
Warning: Cannot read property 'name' of undefined Use --force to continue.
For reference, I tried to use
middleware: function (connect) {
return [
lrSnippet
];
}
where
var lrSnippet = require('connect-livereload')({port: LIVERELOAD_PORT});
Ok, I figured it out. express.compress middleware breaks this.
Essentially, the livereload middleware must be loaded AFTER express.compress. If livereload is loaded prior to compress, it does nothing. However, I'm still not sure why the middleware option is causing the error above.
Also, is there a way to specify where grunt-express automatically injects the connect-livereload script?
Thanks!
@aaronz8 Right now livereload middleware is injected at top of the express middleware stack (I did that by rearranging the middleware by priority and livereload was blindly assigned a priority of -1 https://github.com/blai/grunt-express/blob/master/lib/util.js#L159). I was a bit lazy when I first put this together since if I put livereload middleware at top, it seems to be good for most cases.
I would opt for trying to debug and fix the issue you found around middleware first, and if that does not work well, then it seems I have a 2 ways to go about this:
- add a
LRplaceholderoption to control the position for injecting the middleware - try to play smart and inject the LR middleware right before the first
express.staticmiddleware in the stack
Suggestions?
Sorry about the slow response, as I have not had a chance to debug the middleware issue yet (I've just commented out my express.compress to continue). If you do decide to add this feature, I think the 2nd way would cover all cases, without adding more complexity to the user so I'd go with that one over option 1.
Thanks for all your help!
I'm currently having difficult getting the livereload script to load also...
My gruntfile is setup like this...
express: {
livereload: {
options: {
port: 9000,
livereload: true,
bases: [
'.tmp',
'<%= yeoman.app %>'
],
server: 'server/index.js'
}
}
},
And, there's no livereload script when I view the source at localhost:9000.