如何修复gulp-browser-sync中的无尽重载错误

时间:2019-10-24 06:31:55

标签: gulp browser-sync gulp-watch gulp-browser-sync

我已经创建了一个gulpfile.js来进行快速项目编译。我的结果是:

var gulp = require('gulp'),
    sass = require('gulp-sass'),
    browserSync = require('browser-sync'),
    uglify = require('gulp-uglify'),
    concat = require('gulp-concat'),
    rename = require('gulp-rename');

gulp.task('scss', function(){
  return gulp.src('app/scss/**/*.scss')
    .pipe(sass({outputStyle: 'compressed'}))
    .pipe(rename({
        suffix:'.min'
    }))
    .pipe(gulp.dest('app/css'))
    .pipe(browserSync.reload({stream: true}));
});

gulp.task('html', function(){
  return gulp.src('app/*.html')
    .pipe(browserSync.reload({stream: true}));
});

gulp.task('script', function(){
  return gulp.src('app/js/*.js')
    .pipe(browserSync.reload({stream: true}));
});

gulp.task('js', function(){
  return gulp.src([
    'node_modules/slick-carousel/slick/slick.js',
    'node_modules/magnific-popup/dist/jquery.magnific-popup.js'
  ])
    .pipe(concat('script.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest('app/js'))
    .pipe(browserSync.reload({stream: true}));
});

gulp.task ('browser-sync', function(){
  browserSync.init({
    server: {
      baseDir: "app/"
    }
  });
});

gulp.task('watch', function(){
  gulp.watch('app/scss/**/*.scss', gulp.parallel('scss'));
  gulp.watch('app/*.html', gulp.parallel('html'));
  gulp.watch('app/js/*.js', gulp.parallel('script'));
});

gulp.task('default', gulp.parallel('browser-sync', 'watch'));

但是开始后,我已经对这个问题感到满意-我看到了:

[23:26:38] Starting 'script'...
[Browsersync] 1 file changed (libs.min.js)
[23:26:38] Finished 'script' after 5.66 ms
[Browsersync] Reloading Browsers...
[23:26:40] Starting 'script'...
[Browsersync] 1 file changed (libs.min.js)
[23:26:40] Finished 'script' after 11 ms
[Browsersync] Reloading Browsers...
[23:26:43] Starting 'script'...
[Browsersync] 1 file changed (libs.min.js)
[23:26:43] Finished 'script' after 14 ms
[Browsersync] Reloading Browsers...

为什么存在此重新加载?如何解决? 预先谢谢你!

如果您对此文件优化有任何想法-请让我知道! 谢谢!

0 个答案:

没有答案