【问题标题】:Gulp exits after runningGulp 运行后退出
【发布时间】:2016-07-27 21:19:35
【问题描述】:

我正在尝试使用 gulp 使用快速服务器进行实时重新加载

但是 gulp 运行后退出如下,无法访问服务器

cmd 输出:

D:\Users\workspace\server>gulp 服务器 [11:31:56] 使用 gulpfile D:\Users\workspace\server\gulpfile.js

[11:31:56] 正在启动“服务器”...

[11:31:56] 26 毫秒后完成“服务器”

livereload[tiny-lr] 正在监听 35729 ...

D:\Users\workspace\server>

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

我调用 gulp 的方式有什么根本不正确的地方吗?

【问题讨论】:

  • gulp-express 已被弃用,并且已经一年没有维护了。请改用gulp-live-server
  • 实时重载是什么意思?

标签: node.js express gulp livereload gulp-watch


【解决方案1】:

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

    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')
            });

    }); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-26
    • 1970-01-01
    • 2022-06-23
    • 1970-01-01
    • 1970-01-01
    • 2018-01-24
    相关资源
    最近更新 更多