Created
July 29, 2015 23:40
-
-
Save codekipple/386fd47b0f9b642f839b to your computer and use it in GitHub Desktop.
Gulp example of handling css compilation
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'), | |
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