【问题标题】:BrowserSync only firing in Gulp once on watch, but not on subsequent changesBrowserSync 只在 Gulp 中触发一次,但不会在后续更改中触发
【发布时间】:2016-03-05 19:46:54
【问题描述】:

我正在学习本教程,但在更改 CSS 时无法启动 browserSync。

如果我调用gulp watch,它会重新加载一次,SASS 会自动编译为 CSS,但 browserSync 不会在更改时触发。

以下要点是整个gulpfile.js

https://gist.github.com/RyanNovas/c940324270b57754e487

【问题讨论】:

  • 你把这个排序了吗?
  • 是的,你的工作。谢谢!
  • 如果您觉得它有用,您可以考虑将其选为“正确”。干杯-

标签: node.js gulp-watch browser-sync


【解决方案1】:

看来你不见了

var watch  = require('gulp-watch');

不知道为什么这不会引发错误。无论如何。

这是以下 gulpfile 的一部分,包含相关内容。

// Gulpfile
var gulp            = require('gulp');
var watch           = require('gulp-watch');

// Server
var browserSync     = require('browser-sync').create();
var reload          = browserSync.reload;

// define the default task, call 'serve'.
gulp.task('default', ['serve']);

// Use BrowserSync to fire up a localhost server and start a livereload. We
// inject CSS changes, and reload fully for javascript and html changes.
// http://www.browsersync.io/docs/options/
gulp.task('serve', ['sass', 'webpack'], function() {

    browserSync.init({
        server: "./",
        notify: false,
        reloadOnRestart: true,
        open: false,
    });

    // scss
    gulp.watch("./css/sass/*.scss", ['sass']);
    gulp.watch("./javascript/app/**/*.scss", ['sass']);
    gulp.watch("./css/styles.css").on('change', reload);

    // html
    gulp.watch("./index.html").on('change', reload);
    gulp.watch("./javascript/app/**/*.html").on('change', reload);

    // js
    gulp.watch('./javascript/app/**/*.js', ['webpack']);
    gulp.watch('./javascript/dist/**/*.js').on('change', reload);

});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-08
    • 2017-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多