node.js gulp-livereload在浏览器中没有刷新

时间:2016-04-30 21:30:49

标签: node.js express gulp

我是node.js的新手。使用以下代码时,将修改dist文件夹中的文件时触发重新加载任务。

我有chrome激活的livereload插件。状态为“实时重新加载已连接”。但浏览器不会自动刷新。

此代码中缺少任何内容?

const path = require('path');
const gulp = require('gulp');
const nodemon = require('gulp-nodemon');
const es6Pipeline = require('gulp-webpack-es6-pipeline');
const less = require('gulp-less');
var webserver = require('gulp-webserver');
var livereload = require('gulp-livereload');
es6Pipeline.registerBuildGulpTasks(
    gulp,
    {
        entryPoints: {
            'bundle': path.join(__dirname, '/src/index.js')
        },
        outputDir: path.join(__dirname, 'public/generated/js')
    }
);

gulp.task('live-server', (done) => {
});
gulp.task('test-server', function () {
    var express = require('express'),

        serverport = 5000;


    var server = express();

    server.use(express.static('./dist'));


    server.listen(serverport);
    console.log("Server started at port: " + serverport);
    // Start live reload
    livereload({start: true});

    gulp.watch('dist/*.*', ['reload']);

});

gulp.task('reload', function () {
    console.log("refreshed");
    livereload();

});
gulp.task('generate', ['es6Pipeline:build:release']);
gulp.task('run-release', ['es6Pipeline:build:release', 'test-server']);
gulp.task('run-dev', ['es6Pipeline:build:dev', 'test-server']);
gulp.task('default', ['es6Pipeline:watch', 'test-server']);

1 个答案:

答案 0 :(得分:0)

您是否尝试过以下操作?

gulp.task('reload', function () {
  console.log("refreshed");
  livereload.listen(); 
});