I'm trying to include browsersync functionality to my existing gulpfile.js, but i cannot make it work. Browsed too many gulpfile.js examples now i got more confused. I'm new to gulp and can't find my way around. Any help appreciated.
This is my gulpfile.js:
import gulp from 'gulp' //import browserSync from 'browser-sync' import imagemin from 'gulp-imagemin' import fileinclude from 'gulp-file-include' import dartSass from 'sass' import gulpSass from 'gulp-sass' const sass = gulpSass(dartSass) const browserSync = require('browser-sync').create(); function browsersync() { browserSync.init({ server: { baseDir: 'dist/', }, ghostMode: { clicks: false }, notify: false, online: true, }) } // Optimize images gulp.task('imagemin', async () => { gulp.src('src/images/*') .pipe(imagemin()) .pipe(gulp.dest('dist/assets/img')) }) // File includes gulp.task('fileinclude', async () => { gulp.src(['src/views/**/*.html', '!src/views/**/_*.html']) .pipe(fileinclude({ prefix: '@@', basepath: '@file' })) .pipe(gulp.dest('dist')); }); // Compile Sass gulp.task('sass', async () => { gulp.src('src/sass/**/*.scss', { sourcemaps: true }) .pipe(sass.sync().on('error', sass.logError)) // scss to css .pipe(gulp.dest('dist/assets/css', { sourcemaps: '../sourcemaps/' })) .pipe(browserSync.stream()) }) // Test gulp.task('default', async () => { return console.log('Gulp is running...') }) // GULP WATCH gulp.task('watch', async () => { gulp.watch('src/sass/**/*.scss', gulp.series('sass')) gulp.watch('src/views/**/*.html', gulp.series('fileinclude')).on('change', browserSync.reload) //gulp.watch('src/images/*', ['imagemin']) })