pjlamb12
pjlamb12

Reputation: 2422

Gulp LiveReload Crashing

Our project is using Gulp and LiveReload. I believe we grabbed the code from a starter pack, but I'm not sure. Either way, I didn't put the Gulp setup together.

We are using the gulp-load-plugins to load all the gulp plugins we're using. Each task is in its own file, and is loaded in and run. Here's a gist with the code. That has the Gulpfile.js and the watch.js files. I also added a file there with the output of the error in the terminal when a file is changed. The output says that livereload.changed is not a function, but this link to the gulp-livereload page says that it is a function.

My question is: what is causing the error? Is the watch.on('change', function) outdated? Is there a better, more appropriate way to set that up. In all the other projects I've set livereload up on, I've not used it in this way.

Thanks in advance for your help.

Upvotes: 0

Views: 70

Answers (1)

omarjmh
omarjmh

Reputation: 13888

In your gulp file you use gulp-load-plugins which makes the following code correct:

var server = plugins.livereload();

But in the watch file you use it without requiring it, so just do that and you're fine. the error is that server is undefined, that is why.

Using var server = require('gulp-livereload'); in the watch.js outside of exports will make this work.

I almost always have my watch task in the gulp file and then this isn't a problem. In that case all the plugins are there no need to require/export stuff around to different gulp task files

Upvotes: 1

Related Questions