Skip to content

Instantly share code, notes, and snippets.

@korinVR
Last active September 16, 2016 04:31
Show Gist options
  • Save korinVR/e8ae9d637b8f463844ae to your computer and use it in GitHub Desktop.
Save korinVR/e8ae9d637b8f463844ae to your computer and use it in GitHub Desktop.
Babel + Gulp + Watchify + BrowserSync
var gulp = require("gulp");
var gutil = require("gulp-util");
var notify = require('gulp-notify');
var source = require("vinyl-source-stream");
var buffer = require('vinyl-buffer');
var browserify = require("browserify");
var watchify = require("watchify");
var babelify = require("babelify");
var browserSync = require("browser-sync").create();
var ENTRY_FILE = "./src/main.js";
var OUTPUT_DIR = "./bin";
var OUTPUT_FILE = "output.js";
var DELAY = 50;
gulp.task("watch", function () {
var b = browserify({ entries: [ ENTRY_FILE ] }).transform(babelify);
function bundle() {
b.bundle()
.on("log", gutil.log)
.on("error", notify.onError())
.pipe(source(OUTPUT_FILE))
.pipe(buffer())
.pipe(gulp.dest(OUTPUT_DIR))
.pipe(browserSync.reload({ stream: true }));
}
watchify(b, { delay: DELAY }).on("update", bundle);
bundle();
});
gulp.task("serve", function () {
browserSync.init({
server: {
baseDir: "./"
}
});
});
gulp.task("default", [ "watch", "serve" ]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment