D
D
dhat2016-09-06 15:44:20
css
dhat, 2016-09-06 15:44:20

How to refresh Gulp browser on html change?

I want to make a task for Galp that will refresh browser-sync running from the public folder when I change index.html in the source folder .
My gulpfile.js is like this:

gulp.task('build', function() {
    gulp.src('source/index.html')
    .pipe(gulp.dest('public/'))
    .pipe(reload({stream: true}))
})

gulp.task('server', function() {
    browserSync.init({
        server: {
            baseDir: "public/"
        }
    })
})

Well, i.e. copying from source to public works as it should, but changing the source file index.html does not rebuild its copy in the public folder.
How to correctly configure everything for my task?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergei Nazarenko, 2016-09-06
@nazares

gulp.task('default', ['server'], function(){

gulp.watch(['путь к файлам html'],  browserSync.reload());

});

D
dhat, 2016-09-06
@dhat

Ok, I put it together myself:

gulp.task('buildHTML', function() {
    gulp.src('source/index.html')
    .pipe(gulp.dest('public/'))
    .pipe(reload({stream: true}))
})

gulp.task('watch', function() {
    gulp.watch('source/scss/*.scss', ['compileSass'])
    gulp.watch('source/index.html', ['buildHTML'])
})

gulp.task('server', function() {
    browserSync.init({
        server: {
            baseDir: "public/"
        }
    })
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question