Skip to content

Instantly share code, notes, and snippets.

@koolii
Created October 3, 2015 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koolii/b7bd1fc063376da60128 to your computer and use it in GitHub Desktop.
Save koolii/b7bd1fc063376da60128 to your computer and use it in GitHub Desktop.
import gulp from 'gulp';
import browserify from 'browserify';
import babelify from 'babelify';
import source from 'vinyl-source-stream';
import watchify from 'watchify';
import browserSync from 'browser-sync';
let compile = (isWatch) => {
let bundler = browserify('./src/js/app.js', { debug: true }).transform(babelify);
if (isWatch) {
bundler = watchify(bundler);
bundler.on('update', () => {
console.log('-> partical bundling.');
rebundle();
});
}
rebundle();
function rebundle() {
bundler
.bundle()
.on('error', (err) => {
console.log("Error: " + err.message);
})
.pipe(source('bundle.js'))
.pipe(gulp.dest('./src/js'))
}
};
gulp.task('browserify', () => {
browserify('./src/js/app.js', { debug: true }).transform(babelify)
.bundle()
.on('error', (err) => {
console.log("Bundle Error: " + err.message);
})
.pipe(source('bundle.js'))
.pipe(gulp.dest('./src/js'))
});
gulp.task('browser-sync', () => {
browserSync({
server: {
baseDir: "src"
}
})
gulp.watch("./src/js/bundle.js", () => {
browserSync.reload();
});
});
gulp.task('watch', () => {
compile(true);
});
gulp.task('build', () => {
compile(false);
});
gulp.task('default', ['browser-sync', 'watch']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment