简体   繁体   English

Gulp LiveReload崩溃

[英]Gulp LiveReload Crashing

Our project is using Gulp and LiveReload. 我们的项目正在使用Gulp和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. 无论哪种方式,我都没有将Gulp设置放在一起。

We are using the gulp-load-plugins to load all the gulp plugins we're using. 我们正在使用gulp-load-plugins加载我们正在使用的所有gulp插件。 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. 那有Gulpfile.js和watch.js文件。 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. 输出结果表明livereload.changed不是函数,但是指向 gulp-livereload页面的此链接表明它是函数。

My question is: what is causing the error? 我的问题是:什么原因导致错误? Is the watch.on('change', function) outdated? watch.on('change', function)过时了? 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. 在我设置了livereload的所有其他项目中,我没有以这种方式使用它。

Thanks in advance for your help. 在此先感谢您的帮助。

In your gulp file you use gulp-load-plugins which makes the following code correct: 在您的gulp文件中,您使用gulp-load-plugins可以使以下代码正确:

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'); 使用var server = require('gulp-livereload'); in the watch.js outside of exports will make this work. 在watch.js之外的导出中将使此工作有效。

I almost always have my watch task in the gulp file and then this isn't a problem. 我几乎总是在gulp文件中执行监视任务,这不是问题。 In that case all the plugins are there no need to require/export stuff around to different gulp task files 在这种情况下,所有插件都不需要将内容导出/导出到不同的gulp任务文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM