Created
June 1, 2015 06:49
-
-
Save corysimmons/c6607882d6a858283ee3 to your computer and use it in GitHub Desktop.
Boy gulpfile.js
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
var gulp = require('gulp'), | |
postcss = require('gulp-postcss'), | |
sourcemaps = require('gulp-sourcemaps'), | |
autoprefixer = require('gulp-autoprefixer'), | |
lost = require('lost'), | |
uglify = require('gulp-uglify'), | |
plumber = require('gulp-plumber'), | |
stylus = require('gulp-stylus'), | |
concat = require('gulp-concat'), | |
browserSync = require('browser-sync').create(), | |
minifyCss = require('gulp-minify-css'); | |
// BrowserSync | |
gulp.task('browser-sync', function() { | |
browserSync.init({ | |
server: { | |
baseDir: './' | |
}, | |
notify: false | |
}); | |
gulp.watch('**/*.html').on('change', browserSync.reload); | |
}); | |
// Error handler | |
var errHandler = function(err) { | |
gutil.beep(); | |
console.log(err); | |
}; | |
// Styles | |
gulp.task('styles', function() { | |
return gulp.src('src/css/**/*.styl') | |
.pipe(plumber({ | |
errorHandler: errHandler | |
})) | |
.pipe(sourcemaps.init()) | |
.pipe(stylus()) | |
.pipe(postcss([ | |
lost() | |
])) | |
.pipe(autoprefixer()) | |
.pipe(minifyCss()) | |
.pipe(sourcemaps.write('./')) | |
.pipe(gulp.dest('dist/css/')) | |
.pipe(browserSync.reload({ stream: true }));; | |
}); | |
// Copy JS vendor assets to dist/js/vendor/ | |
gulp.task('copy-scripts', function() { | |
return gulp.src('src/js/vendor/**/*.js') | |
.pipe(gulp.dest('dist/js/vendor/')); | |
}); | |
// JavaScript | |
gulp.task('scripts', ['copy-scripts'], function() { | |
return gulp.src(['src/js/**/*.js', '!src/js/vendor/**.*.js']) | |
.pipe(plumber({ | |
errorHandler: errHandler | |
})) | |
.pipe(sourcemaps.init()) | |
.pipe(uglify()) | |
.pipe(concat('all.js')) | |
.pipe(sourcemaps.write('./')) | |
.pipe(gulp.dest('dist/js/')) | |
.pipe(browserSync.reload({ stream: true }));; | |
}); | |
// Watch tasks | |
gulp.task('watch', function() { | |
gulp.watch('src/css/**/*.*', ['styles']); | |
gulp.watch('src/js/**/*.js', ['scripts']); | |
}); | |
gulp.task('default', ['browser-sync', 'styles', 'scripts', 'watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment