Skip to content

Instantly share code, notes, and snippets.

@luv2code
Created August 15, 2017 20:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luv2code/77ddbc79c02d40194f929841d0696ebc to your computer and use it in GitHub Desktop.
Save luv2code/77ddbc79c02d40194f929841d0696ebc to your computer and use it in GitHub Desktop.
gulp file with browserify uglify watchify source maps and livereload
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