Skip to content

Instantly share code, notes, and snippets.

@BrockReece
Last active November 1, 2015 10:54
Show Gist options
  • Save BrockReece/21181adc1854d6c4c221 to your computer and use it in GitHub Desktop.
Save BrockReece/21181adc1854d6c4c221 to your computer and use it in GitHub Desktop.
Simple gulp file for linting and minifying js, compiling sass and deploying all to dist dir
var gulp = require('gulp');
var jshint = require('gulp-jshint'),
sass = require('gulp-sass'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
minifycss = require('gulp-minify-css'),
del = require('del');
var stylesSrc = 'src/sass',
stylesDist = 'dist/css';
var scriptSrc = 'src/js',
scriptDist = 'dist/js';
var htmlSrc = 'src/html',
htmlDist = 'dist';
var copy = function(src, dest, base) {
return gulp.src(src, {base: base})
.pipe(gulp.dest(dest));
};
gulp.task('lint', function() {
return gulp.src(scriptSrc + '/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('styles', function() {
return gulp.src(stylesSrc + '/*.scss')
.pipe(sass())
.pipe(gulp.dest(stylesDist))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest(stylesDist));
});
gulp.task('scripts', function() {
return gulp.src([scriptSrc + '/router.js', scriptSrc + '/*.js'])
.pipe(concat('all.js'))
.pipe(gulp.dest(scriptDist))
.pipe(rename('all.min.js'))
.pipe(uglify())
.pipe(gulp.dest(scriptDist));
});
gulp.task('html', function() {
return copy(htmlSrc + '/**/*', htmlDist, htmlSrc);
});
gulp.task('clean', function(cb) {
del([stylesDist, scriptDist], cb);
});
gulp.task('watch', function() {
gulp.watch(scriptSrc + '/*.js', ['lint', 'scripts']);
gulp.watch(stylesSrc + '/*.scss', ['styles']);
gulp.watch(htmlSrc + '/**/*', ['html']);
});
gulp.task('default', ['clean'], function() {
gulp.start('lint', 'styles', 'scripts', 'html');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment