Following the usage part of the gulp-express specifications I'm trying to setup an express development server with livereload. I have separate tasks that do javascript uglification, transform scss to css and minify html, so I only need to run the server from my dist folder.
So far everything works, except livereload (the browser does not reload upon css changes).
My gulp task:
gulp.task('server', function() {
server.run(['main.js'],[],[1337]);
gulp.watch(['/dist/**/*.html'], server.notify);
gulp.watch(['/dist/**/*.css'], server.notify);
gulp.watch(['/dist/**/*.js'], server.notify);
gulp.watch(['/dist/assets/images/*.*'], server.notify);
});
main.js:
// packages
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var morgan = require('morgan');
var path = require('path');
//app configuration
// body parser
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
//CORS requests
app.use(function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With, content-type, Authorization');
next();
});
//log all requests to console
app.use(morgan('dev'));
app.use(express.static(__dirname + '/dist'));
//catchall route
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname + '/dist/index.html'));
});
//start the server
app.listen(1337);
console.log('Running on port 1337!');
When running gulp server I get the following message in the console:
livereload[tiny-lr] listening on 35729 ... Running on port 1337!
I can load the page in the browser, but it won't auto-refresh on code change.
What am I doing wrong?