I managed to get Grunt.js successfully live-reloading according to changes made to client-side code (html, css, js) using plugins: grunt-express, grunt-contrib-watch and grunt-open. I started running into trouble when trying to make the live-reloading scheme compliant with changes to server-side js code.
I have the following Grunt tasks:
express: {
all: {
options: {
bases: ['./public'],
server: "app.js",
port: 3000,
hostname: "0.0.0.0",
livereload: true
}
}
},
open: {
all: {
path: 'http://localhost:3000/index.html'
}
},
watch: {
all: {
files: [
'public/**/*.html',
'public/src/js/*.js',
'public/src/css/*.css',
'app.js',
],
options: {
livereload: true,
interrupt: true
}
}
}
These tasks are fired off with the following command:
grunt.registerTask('server', [
'express',
'open',
'watch'
]);
Interestingly enough, an express endpoint with the above code (which returns a JSONified array): "/test" results in a "404" error. After adding a server attribute to the express options I was able to get the array from the "/test" endpoint:
options: {
bases: ['./public'],
server: "app.js",
port: 3000,
hostname: "0.0.0.0",
livereload: true
}
However, the page still refuses to live reload (even when then client side code that was live-reloading before changed). When I make a simple change to client-side html, css, js I need to press F5 in order for the browser to reflect the changes. If I try to alter the items in the array that the "/test" endpoint is returning on the server side, I need to stop the grunt watch task, and rerun the grunt server task specified above.
Even though I believe this is a Grunt issue, I will post the server-side code I have in my app.js file:
var express = require('express');
//create instance of app
var app = express();
app.use(express.static(__dirname + '/public'));
app.get('/test', function(request, response){
response.json(['test1','test2','test3', 'test4']);
});
module.exports = app;
Any help on how to get Grunt to recognize the changes I am making to server-side/client-side files would be much appreciated!
I've looked at the following sources and questions:
Grunt-Contrib-Connect @ npm as an alternative to Grunt-Express & Grunt-Open
Aucun commentaire:
Enregistrer un commentaire