javascript - gulp-live-server 不刷新页面

标签 javascript node.js gulp gulp-livereload

我正在尝试使用 gulp-live-server 来自动重启我的服务器并在我的代码更改时刷新页面。

这是我的基本设置:

在我的 server.js 上:

app.use(require('connect-livereload')());

我的 gulp 文件:

gulp.task('server', function () {
   server = gls('app.js', options);
    server.start();

    // Watch for file changes
    gulp.watch(['app.js', 'app/**/*.js', 'config/**/*.js', 'components/**/*.jsx'], function() {
        server.start.bind(server)();
        server.notify.bind(server)();
    });
});

我的服务器成功重启,但浏览器从未刷新。

感谢您的帮助。

最佳答案

尝试在调用通知时传递文件:

gulp.task('server', function () {
   server = gls('app.js', options);
    server.start();

    // Watch for file changes
    gulp.watch(['app.js', 'app/**/*.js', 'config/**/*.js', 'components/**/*.jsx'], function(file) {
        server.start.bind(server)();
        server.notify.bind(server)(file);
    });
});

关于javascript - gulp-live-server 不刷新页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33578125/

相关文章:

javascript - 为什么 javascript 不从 fetch 中解析 HTML?

javascript - Tau-Prolog 解释器表现出与 SWI-Prolog 不同的行为

javascript - 用 sinon 监视 Date 构造函数

node.js - Mongoose Populate 无法让它工作?

sql - 如何将 NodeJS 变量输入到 SQL 查询中

npm - 管理分发供应商

javascript - 移动滚动时延迟元素位置更新

javascript - 关闭弹出窗口然后转到父级中的 URL

javascript - 将匿名函数中的 javascript 与 gulp 连接起来

javascript - Full Gulp Istanbul 尔报道报告