Skip to content

Instantly share code, notes, and snippets.

@nicekiwi
Created March 7, 2017 13:45
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save nicekiwi/ca575492dfd83504aced26892c559d58 to your computer and use it in GitHub Desktop.
Save nicekiwi/ca575492dfd83504aced26892c559d58 to your computer and use it in GitHub Desktop.
New ES6 project with Babel, Browserify & Gulp + Bundling/Watching Multiple Files
import gulp from 'gulp';
import sourcemaps from 'gulp-sourcemaps';
import buffer from 'gulp-buffer';
import uglify from 'gulp-uglify';
import tap from 'gulp-tap';
import browserify from 'browserify';
import babel from 'babelify';
gulp.task('build', () => {
return gulp.src('./assets/js/*.js', { read: false })
.pipe(tap((file) => {
file.contents = browserify(file.path, {
debug: true
}).transform(babel, {
presets: [ 'es2015' ]
}).bundle();
}))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./public/assets/js/'));
});
gulp.task('watch', function () {
gulp.watch('./assets/js/**/*.js', ['build']);
});
gulp.task('default', ['build', 'watch']);
@pyronaur
Copy link

Thank you! Took me an hour to find this.
How is this process still a thing in 2017!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment