Created
April 16, 2015 02:34
-
-
Save jeffstagg/2585aee8899b75ed4eb4 to your computer and use it in GitHub Desktop.
Less Server-Side with Gulp
This file contains 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
module.exports = function() { | |
var config = { | |
//CSS | |
cssOutput: './Common/Styles/min', | |
less: './Common/Styles/less/**/*.less', | |
}; | |
return config; | |
}; |
This file contains 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'), | |
config = require('./gulp.config')(), | |
less = require('gulp-less'), | |
minifyCss = require('gulp-minify-css'), | |
concat = require('gulp-concat'), | |
rename = require('gulp-rename'), | |
clean = require('gulp-clean'), | |
uglify = require('gulp-uglify'), | |
rename = require('gulp-rename'), | |
$ = require('gulp-load-plugins')({lazy: true}); | |
//precompile less | |
gulp.task('less', ['cleanCss'], function() { | |
console.log('Converting LESS ---> CSS'); | |
return gulp | |
.src(config.less) | |
.pipe($.less()) | |
.pipe(gulp.dest(config.cssOutput)) | |
.pipe(concat('styles.css')) | |
.pipe(gulp.dest(config.cssOutput)); | |
}); | |
//remove CSS files from output directory | |
gulp.task('cleanCss', function() { | |
console.log('Cleaning CSS output directory...'); | |
return gulp.src(config.cssOutput, {read: false}) | |
.pipe(clean({force: true})); | |
}); | |
//watch css directory | |
gulp.task('watchCss', function() { | |
console.log('Starting CSS watch.'); | |
gulp.watch([config.less], ['cleanCss', 'less']); | |
}) | |
gulp.task('default', function() { | |
gulp.run('less'); | |
gulp.watch([config.less], ['cleanCss', 'less']); | |
}); |
This file contains 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
{ | |
"name": "Example", | |
"version": "1.0", | |
"description": "Example to demonstrate Gulp to compile LESS", | |
"authors": [ | |
"Jeff Stagg" | |
], | |
"scripts": { | |
"init": "npm install" | |
}, | |
"devDependencies": { | |
"gulp": "^3.8.11", | |
"gulp-clean": "^0.3.1", | |
"gulp-concat": "^2.5.2", | |
"gulp-dest": "^0.2.2", | |
"gulp-less": "^3.0.2", | |
"gulp-load-plugins": "^0.9.0", | |
"gulp-minify-css": "^1.0.0", | |
"gulp-rename": "^1.2.2", | |
"gulp-uglify": "^1.1.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment