Created
August 22, 2022 20:29
-
-
Save satsie/db22f92c2091187ade3f5f911b74a91e to your computer and use it in GitHub Desktop.
Gulp: reload browserify with browser-sync
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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