Unfortunately, grunt-contrib-watch and grunt-contrib-connect don't seem to be playing nice.
On the grunt-contrib-connect readme it says:
Note that this server only runs as long as grunt is running. Once grunt's tasks have completed, the web server stops. This behavior can be changed with the keepalive option, and can be enabled ad-hoc by running the task like grunt connect::keepalive.
Fine. But what if I want to run my watch task in tandem with the connect server? Like so:
connect: {
server: {
options: {
port: 8000,
hostname: 'localhost',
keepalive: true
}
}
},
watch: {
options: {
livereload: true
},
files: ['**'],
tasks: ['connect'],
}
Here, the connect
task runs when a file is changed. If I set the connect's keepalive
option to true, then grunt-contrib-watch stops watching because it technically hasn't finished it's task. If I falsify the keepalive
option, then the connect server dies after it has finished the tasks.
Yes, I could run the commands...
$ grunt connect
$ grunt watch
...in separate shells, but is there no way of running them with one command?
I use grunt-nodemon, which encapsulates watch and a nodejs launcher in a single task:
Then executed with:
Now, nodemon only launches the app.js script with nodejs, so you will need a small app.js to load a static static express server: