2016-04-07 263 views
0

我试图让现场的重载使用一饮而尽咕嘟咕嘟运行

但是运行之后,如下吞掉退出,我不能够打到服务器Express服务器工作后退出

CMD输出:

d:\ Users \用户工作空间\服务器>吞服务器 [11时31分56秒]使用gulpfile d:\ Users \用户工作空间\服务器\ gulpfile.js

[11时31分56秒]启动 '服务器' ...

[十一时31分56秒]后26毫秒

livereload [微小-LR]侦听35729 ...

d成品 '服务器':\ Users \用户工作空间\服务器>

gulpfile.js:

var gulp = require('gulp'); 
var server = require('gulp-express'); 

gulp.task('server', function() { 
    // Start the server at the beginning of the task 
server.run(['app.js']); 

// Restart the server when file changes 
gulp.watch(['app/**/*.html'], server.notify); 
gulp.watch(['app/styles/**/*.scss'], ['styles:scss']); 
//gulp.watch(['{.tmp,app}/styles/**/*.css'], ['styles:css', server.notify]); 
//Event object won't pass down to gulp.watch's callback if there's more than one of them. 
//So the correct way to use server.notify is as following: 
gulp.watch(['{.tmp,app}/styles/**/*.css'], function(event){ 
    gulp.run('styles:css'); 
    server.notify(event); 
    //pipe support is added for server.notify since v0.1.5, 
    //see https://github.com/gimm/gulp-express#servernotifyevent 
}); 

gulp.watch(['app/scripts/**/*.js'], ['jshint']); 
gulp.watch(['app/images/**/*'], server.notify); 
gulp.watch(['app.js', 'routes/**/*.js'], [server.run]); 
}); 

gulp.task('default', ['server']); 

gulpjs tutplus

在我打电话的时候,有没有根本不正确的东西?

+1

'gulp-express'已弃用,并且一直未维护一年。改用['gulp-live-server'](https://github.com/gimm/gulp-live-server)。 –

+0

你是什么意思现场重新加载? – gh0st

回答

0

即使我有一些问题得到实时重新加载工作。因此,我开始使用gulp-nodemon来创建Web服务器并实时重新加载。以下是我的任务:

gulp.task('server', function(){ 
     var nodeOptions = { 
      script:"",//path to the app.js or server.js 
      delayTime: 1, 
      env: { 
       'PORT': 8088 //port that you want to run it on 
      }, 
      watch: ['filesToBeWatched.js'] //files to be watched for changes 
     }; 

     return nodemon(nodeOptions) 
      .on('restart', function(event){ 
       console.log('Node Server RESTARTED'); 
      }) 
      .on('start', function(){ 
       console.log('Node Server STARTED'); 
       startBrowserSync(); 
      }) 
      .on('crash', function() { 
       console.log('Node Server CRASHED'); 
      }) 
      .on('exit', function() { 
       console.log('Node Server EXISTED') 
      }); 

    });