我是新手,我正尝试使浏览器同步正常工作。除了同步滚动条不起作用外,它似乎工作正常。谁能看到我的设置有什么问题吗?

var gulp = require('gulp'),
    jade = require('gulp-jade'),
    uglify = require('gulp-uglify'),
    gutil = require('gulp-util'),
    sass = require('gulp-sass'),
    livereload = require('gulp-livereload'),
    browserSync = require('browser-sync');

var outputDir = "builds/development";

gulp.task('jade', function() {
    return  gulp.src('src/templates/**/*.jade')
        .pipe(jade())
        .pipe(gulp.dest(outputDir))
        .pipe(livereload());
});

// Js - to uglify use gulp js --type production ( or just leave out js to build everything )
gulp.task('js', function() {
    return gulp.src('src/js/main.js')
        .pipe(gutil.env.type === 'production' ? uglify() : gutil.noop())
        .pipe(gulp.dest(outputDir + '/js'))
        .pipe(livereload());
});

// Sass - to compress use gulp sass --type production ( or just leave out sass to build everything )
gulp.task('sass', function() {
    var config = {};
    if ( gutil.env.type === 'production') {
        config.outputStyle = 'compressed';
    }
    return gulp.src('src/sass/main.scss')
        .pipe(sass(config))
        .pipe(gulp.dest(outputDir + '/css'))
        .pipe(livereload());
});

// Browser Sync ( not working 100% ... not scrolling )
gulp.task('browser-sync', function() {
    browserSync({
        proxy: "http://localsandbox.dev/gulptutorial/builds/development/"
    });
});




// Watch
gulp.task('watch', function() {
    gulp.watch('src/templates/**/*.jade', ['jade']);
    gulp.watch('src/js/**/*.js', ['js']);
    gulp.watch('src/sass/**/*.scss', ['sass']);
});


gulp.task('default', ['jade', 'js', 'sass', 'watch', 'browser-sync'], function () {
    gulp.watch("js/*.js", ['js', browserSync.reload]);
});

最佳答案

您的问题可能与同时使用Gulp和BrowserSync进行观看有关。这是一个很好的参考:


  “您不应该使用BrowserSync + Gulp观看文件” https://github.com/shakyShane/gulp-browser-sync/issues/16#issuecomment-43597240


因此,您可能希望删除livereload(让BrowserSync处理所有内容)并将默认的Gulp任务更改为以下内容:

gulp.task('default', ['jade', 'js', 'sass', 'browser-sync'], function () {
    gulp.watch('src/templates/**/*.jade', ['jade', browserSync.reload]);
    gulp.watch('src/js/**/*.js', ['js', browserSync.reload]);
    gulp.watch('src/sass/**/*.scss', ['sass', browserSync.reload]);
});


您也可以尝试显式设置滚动(但无论如何默认为true):

gulp.task('browser-sync', function() {
    browserSync({
        proxy: "http://localsandbox.dev/gulptutorial/builds/development/"
        ghostMode: {
          scroll: true
        }
    });
});

关于javascript - Browsersync不同步滚动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27766350/

10-11 23:36