Closed simevidas closed 9 years ago
Update: As a temporary workaround, I’m performing these steps:
.pipe(livereload())
at the end of my CSS and JS build streams. This works OK, I just have to call livereload.listen()
after server.run()
.Hi all, same problem here :( @simevidas your workaround it seems not work
'use strict';
var gulp = require('gulp');
var server = require('gulp-express');
var concat = require('gulp-concat');
var ngAnnotate = require('gulp-ng-annotate');
var livereload = require('gulp-livereload');
require('./gulp/config');
gulp.task('scripts', function () {
return gulp.src(config.paths.src.scripts)
.pipe(concat(config.filenames.scripts))
.pipe(ngAnnotate())
.pipe(gulp.dest(config.paths.dest.build.scripts))
.pipe(livereload());
});
gulp.task('serve', function () {
// Start the server at the beginning of the task
server.run({
file: 'server.js',
port: 45729
});
livereload.listen();
gulp.watch(config.paths.src.scripts, ['scripts', server.notify]);
});
gulp.task('default', ['serve']); //
I always get
node_modules/gulp-express/index.js:80 var fileName = require('path').relative(__dirname, event.path); TypeError: Cannot read property 'path' of null
@whisher I’m using livereload()
as a replacement for server.notify
. So, in your case, the watch call should invoke the "scripts" task, and nothing more:
gulp.watch(config.paths.src.scripts, ['scripts']);
Note: I have the livereload.js script manually included in my website, via:
<script src="//localhost:35729/livereload.js"></script>
at the bottom of my HTML pages.
mmm like this it works :)
var scriptsWatcher = gulp.watch(config.paths.src.scripts, ['scripts']);
scriptsWatcher.on('change', server.notify);
You should put
app.use(require('connect-livereload')());
in your express file
Hello simevidas and whisher, I've just verified the issue, the 'event' is passed to notify correctly with the path value. Could you please provide more details here so that I can reproduce the issue you have?
Hello gimm, node v0.10.33 npm 1.4.28 gulp 3.8.10 in my example
//this work
var scriptsWatcher = gulp.watch(config.paths.src.scripts, ['scripts']);
scriptsWatcher.on('change', server.notify);
//this doesn't work
/*node_modules/gulp-express/index.js:80
var fileName = require('path').relative(__dirname, event.path);
TypeError: Cannot read property 'path' of null*/
var scriptsWatcher = gulp.watch(config.paths.src.scripts, ['scripts',server.notify]);
@whisher @simevidas Yes, you're right. The event object is not passed to the callback (server.notify) if there's multiple ones, like this:
gulp.watch(config.paths.src.scripts, ['scripts',server.notify]); // two callbacks here
According to gulp.watch, in order to make sure the callbacks get the event object, we need to:
var fileWatcher = gulp.watch('files to watch', callback1);
fileWatcher.on('change', callback2);
or
gulp.watch(['files to wach'], function (event) {
callback1(event);
callback2(event);
});
I have updated the readme, thanks man!
In your README, you have this line in the code example:
It seems that this code is invalid. The event with the "path" property is not passed to the
server.notify
method. I get a "TypeError: Cannot read property 'path' of null".My full gulpfile.js is: