-
-
Save wlkns/cae50a9ee8ed820e2f499d9f041c3a79 to your computer and use it in GitHub Desktop.
New ES6 project with Babel, Browserify & Gulp + Bundling/Watching Multiple Files
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
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