Skip to content

Instantly share code, notes, and snippets.

@seanmavley
Created June 20, 2016 22:18
Show Gist options
  • Save seanmavley/3968550de2514a188028c3721c0cecd1 to your computer and use it in GitHub Desktop.
Save seanmavley/3968550de2514a188028c3721c0cecd1 to your computer and use it in GitHub Desktop.
Reset build folder before gulp build then restart browser
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var del = require('del'); // rm -rf
var browser = require('browser-sync').create();
var port = process.env.SERVER_PORT || 3000;
gulp.task('clean', function() {
return del(['app/build']);
});
gulp.task('scripts', ['clean'], function() {
var stream = gulp.src(['app/**/*.js', '!app/vendor/', '!app/vendor/**'])
.pipe(concat('codeside.js'))
.pipe(gulp.dest('app/build'))
.pipe(rename('codeside.min.js'))
.pipe(uglify())
.pipe(gulp.dest('app/build'));
return stream;
});
gulp.task('build', ['scripts']);
// templates and styles will be processed in parallel.
// clean will be guaranteed to complete before either start.
// clean will not be run twice, even though it is called as a dependency twice.
gulp.task('serve', ['build'], function() {
browser.init({ server: 'app/', port: port });
// watch and rebuild scripts
gulp.watch(['app/**/*.js', '!app/build/', '!app/build/**'], ['build'])
.on('change', browser.reload);
});
gulp.task('default', ['serve']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment