Created
March 7, 2017 13:45
-
-
Save nicekiwi/ca575492dfd83504aced26892c559d58 to your computer and use it in GitHub Desktop.
New ES6 project with Babel, Browserify & Gulp + Bundling/Watching Multiple Files
This file contains 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
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']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! Took me an hour to find this.
How is this process still a thing in 2017!