Created
August 15, 2017 20:45
-
-
Save luv2code/77ddbc79c02d40194f929841d0696ebc to your computer and use it in GitHub Desktop.
gulp file with browserify uglify watchify source maps and livereload
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 babel from 'babelify' | |
import watchify from 'gulp-watchify' | |
import livereload from 'gulp-livereload' | |
let watching = false | |
let bundlePaths = { | |
src: [ | |
'src/**/*.js', | |
'!src/**/*.test.js' | |
], | |
dest:'dist/' | |
} | |
gulp.task('enable-watch-mode', () => { watching = true }) | |
gulp.task('enable-livereload', () => livereload.listen()) | |
gulp.task('build', watchify(function(watchify) { | |
return gulp.src(bundlePaths.src) | |
.pipe(watchify({ | |
watch:watching, | |
debug:true, | |
setup: (bundle) => { | |
bundle.transform(babel, { | |
presets: [ 'env' ] | |
}) | |
} | |
})) | |
.pipe(buffer()) | |
.pipe(sourcemaps.init({ loadMaps: true })) | |
.pipe(uglify()) | |
.pipe(sourcemaps.write('./')) | |
.pipe(gulp.dest(bundlePaths.dest)) | |
.pipe(livereload()) | |
})) | |
gulp.task('watch', ['enable-watch-mode', 'enable-livereload', 'build']) | |
gulp.task('default', ['build']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment