browserSync works without sass file

92 Views Asked by At

The browserSync runs fine but the sass isn't getting reloaded and I can't see my changes reloads automatically in the browser. Basically It doesn't reload when I re-run gulp start in the terminal. I'm using Gulp 4, here is my index.js.

Help me Thanks !

gulp.task('style', () => {
    console.log('execute sass file');

    return gulp.src('src/assets/scss/styles.scss')
        .pipe(rename('css/styles.css'))
        .pipe(gulp.dest('dist/css'));
});

gulp.task('index', () => {
    console.log('execute twig');

    return gulp.src('src/markup/index.twig')
    .pipe(rename('html/index.html'))
    .pipe(gulp.dest('dist/html'))
});


gulp.task('twig', function() {

    return gulp.src('src/markup/*.twig')
    .pipe(twig())
    .pipe(gulp.dest('dist/html'))
    .pipe(browserSync.reload({
        stream: true
    }))
});

gulp.task('sass', function () {

    return gulp.src('src/assets/scss/*.scss')
    .pipe(sass())
    .pipe(gulp.dest('dist/css'))
    .pipe(browserSync.reload({
        stream: true
    }))
});

gulp.task('watch', function() {
    gulp.watch('src/assets/scss/**/*.scss', gulp.task('style'));
    gulp.watch('src/markup/index.twig', gulp.task('twig'));
    console.log('task twig and sass works');

    gulp.watch('src/markup/*.twig', browserSync.reload);
    gulp.watch('src/assets/scss/*.scss', browserSync.reload);
});

gulp.task('browser-sync', () => {
    browserSync.init({
        server: {
            baseDir: 'dist/html/',
            browser:"google chrome",
            open: true,
        }
    });
});

gulp.task('start', gulp.parallel('browser-sync','twig', 'sass', 'watch'));

1

There are 1 best solutions below

0
On

Change from:

gulp.watch('src/assets/scss/**/*.scss', gulp.task('style'));  

to

gulp.watch('src/assets/scss/**/*.scss', gulp.series('style'));

You'll want to do that to your twig task as well.