Skip to content

Instantly share code, notes, and snippets.

@codekipple
Created July 29, 2015 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codekipple/386fd47b0f9b642f839b to your computer and use it in GitHub Desktop.
Save codekipple/386fd47b0f9b642f839b to your computer and use it in GitHub Desktop.
Gulp example of handling css compilation
var Gulp = require('gulp'),
pkg = require('./../../package.json'),
Sass = require('gulp-sass'),
Postcss = require('gulp-postcss'),
Autoprefixer = require('autoprefixer-core'),
BrowserSync = require('browser-sync');
var cssCompile = function(devMode) {
var outputStyle;
var processors = [
Autoprefixer({browsers: ['last 2 versions', '> 1%', 'ie 8']}),
];
if (devMode) {
outputStyle = 'expanded';
} else {
outputStyle = 'compressed';
}
/*
Styles
------
1. use .scss files
2. run sass on them
3. Pass the output to postcss
4. Write css to disk
5. Pass css to browsersync
*/
return Gulp.src(pkg.sass + '/**/*.scss') /* 1*/
.pipe(Sass({
outputStyle: outputStyle
}).on('error', function(error) {
// swallow error so watch can continue running
console.log(error.toString());
this.emit('end');
})) /* 2 */
.pipe(Postcss(processors)) /* 3 */
.pipe(Gulp.dest(pkg.css)) /* 4 */
.pipe(BrowserSync.stream()); /* 5 */
}
Gulp.task('styles:prod', function() {
return cssCompile();
});
Gulp.task('styles:dev', function() {
return cssCompile(true);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment