Skip to content

Instantly share code, notes, and snippets.

@satsie
Created August 22, 2022 20:29
Show Gist options
  • Select an option

  • Save satsie/db22f92c2091187ade3f5f911b74a91e to your computer and use it in GitHub Desktop.

Select an option

Save satsie/db22f92c2091187ade3f5f911b74a91e to your computer and use it in GitHub Desktop.
Gulp: reload browserify with browser-sync
const gulp = require('gulp');
const browserify = require('browserify');
const source = require('vinyl-source-stream');
var browserSync = require('browser-sync').create();
// Browserify basically allows the code to use npm modules
gulp.task('browserify', function() {
return browserify('js/scripts.js')
.bundle()
//Pass desired output filename to vinyl-source-stream
// This is the file that index.js is looking for
.pipe(source('js/bundle.js'))
// Start piping stream to tasks!
.pipe(gulp.dest('./'))
.pipe(browserSync.stream());
});
gulp.task('browser-sync', function() {
browserSync.init({
server: {
baseDir: "./"
}
});
gulp.watch("*.html").on("change", browserSync.reload);
gulp.watch("./js/scripts.js", gulp.series('browserify'));
});
gulp.task('build', gulp.series('browserify', 'browser-sync'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment