Last active
August 29, 2015 14:24
-
-
Save web-zen/96292b9bd0e26c60d18b to your computer and use it in GitHub Desktop.
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
// Load Gulp and Plugins | |
var gulp = require('gulp'), | |
browserSync = require('browser-sync').create(), | |
$ = require('gulp-load-plugins')({ lazy: true }); | |
// Paths | |
var path = { | |
lessWatch: 'assets/less/**/*.less', | |
lessSrc: 'assets/less/sites/*.less', | |
cssDest: 'assets/css/sites/', | |
csHtml: 'views/**/*.cshtml' | |
}; | |
// Less | |
var LessPluginCleanCSS = require("less-plugin-clean-css"), | |
cleancss = new LessPluginCleanCSS({ advanced: false }); | |
var LessPluginAutoPrefix = require('less-plugin-autoprefix'), | |
autoprefix = new LessPluginAutoPrefix({ browsers: ["last 2 versions"] }); | |
gulp.task('less', function () { | |
console.log("in less task"); | |
gulp.src(path.lessSrc) | |
.pipe($.plumber()) | |
.pipe($.debug()) | |
.pipe($.changed(path.cssDest, { extension: '.css' })) | |
.pipe($.bytediff.stop(function (data) { | |
var difference = (data.savings > 0) ? ' smaller.' : ' larger.'; | |
return data.fileName + ' is ' + data.percent.toFixed(2) + '%' + difference; | |
})) | |
.pipe(gulp.dest(path.cssDest)) | |
.pipe(browserSync.stream()); | |
}); | |
// Browser Sync | |
gulp.task('browserSync', function () { | |
browserSync.init({ | |
port: 8080, | |
files: [path.cssDest, path.csHtml] | |
}); | |
}); | |
// Default | |
gulp.task('default', ['less', 'watch', 'browserSync']); | |
// Watch | |
gulp.task('watch', function () { | |
gulp.watch(path.lessWatch, { interval: 500 }, ['less']); // set interval above default 100ms to prevent CPU spiking over 50% | |
gulp.watch(path.csHtml).on('change', browserSync.reload); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment