问题描述
我正在尝试设置我的 gulpfile.js
在快速服务器上使用livereload而不用运气。我看到例子,但它们似乎与静态文件服务器有关。
所以我有一个 app.js
文件,它使用玉石文件进行标准快递服务器,我想做的是让它与gulp.js启动的livereload一起工作。
app.set(' port',process.env.PORT || 3000);
var server = app.listen(app.get('port'),function(){
debug('Express server listening on port'+ server.address()。port);
});
有很多插件,如 gulp-livereload
, connect-livereload
, gulp-connect
, gulp-watch
所以我该怎么弄到这个连线?
我添加了代码
-
检测服务器文件中的更改,并通过重新加载服务器
-
等待进程重新加载几秒钟,以使服务器有时间运行其初始化代码。
-
触发livereload服务器中的更改
note 1 :您的构建还应包含一个livereload服务器,并在调用'serve'任务之前将livereload脚本附加到html文件。
note 2 :这是一个永远不会结束的异步任务,不要将其用作其他任务的依赖
功能(cb){
nodemon({
脚本:<服务器启动文件>
手表:< server files>
//...add nodeArgs:['--debug = 5858']调试
//..or nodeArgs:['--debug-brk = 5858']在服务器启动时进行调试
})。on('start',function(){
setTimeout(function(){
livereload.changed();
},2000); //等待服务器在重新启动浏览器之前完成加载
});
});
I am trying to setup my gulpfile.js
to use livereload on an express server without much luck. I see examples out there but they seem to be related to a static file server.
http://code.tutsplus.com/tutorials/gulp-as-a-development-web-server--cms-20903http://rhumaric.com/2014/01/livereload-magic-gulp-style/
So I have an app.js
file which does the standard express server with jade files, etc. What I want to do is get it to work with livereload from a gulp.js boot.
app.set('port', process.env.PORT || 3000);
var server = app.listen(app.get('port'), function() {
debug('Express server listening on port ' + server.address().port);
});
There are lots of plugins like gulp-livereload
, connect-livereload
, gulp-connect
, gulp-watch
so how can I get this wired up?
I've added code that
Detects changes in server files and reloads the server via nodemon
Waits for a couple seconds after process reload in order to give the server time to run its initialization code.
Triggers a change in a livereload server
note 1 : Your build should also include a livereload server and attach livereload scripts to html files before calling the 'serve' task
note 2: This is an asynchronous task that never ends, do not use it as a dependency of other tasks
gulp.task('serve', function (cb) {
nodemon({
script : <server start file>,
watch : <server files>
//...add nodeArgs: ['--debug=5858'] to debug
//..or nodeArgs: ['--debug-brk=5858'] to debug at server start
}).on('start', function () {
setTimeout(function () {
livereload.changed();
}, 2000); // wait for the server to finish loading before restarting the browsers
});
});
这篇关于gulp.js livereload与快递服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!