Skip to content

Instantly share code, notes, and snippets.

@nicksheffield
Created August 19, 2016 03:44
Show Gist options
  • Save nicksheffield/7b8525973ab4cf59e4cce1c4c93061f0 to your computer and use it in GitHub Desktop.
Save nicksheffield/7b8525973ab4cf59e4cce1c4c93061f0 to your computer and use it in GitHub Desktop.
Gulp with sass or stylus
var gulp = require('gulp')
var minify = require('gulp-clean-css')
var autoprefix = require('gulp-autoprefixer')
var rename = require('gulp-rename')
var stylus = require('gulp-stylus')
var sass = require('gulp-sass')
var plumber = require('gulp-plumber')
var notify = require('gulp-notify')
var gulpif = require('gulp-if')
var path = require('path')
var paths = {
css: {
files: 'before/*.styl',
main: 'before/style.styl'
},
output: 'after/'
}
var plumberOpts = {
errorHandler: notify.onError("Error: <%= error.message %>")
}
gulp.task('css', function() {
var stream = gulp.src(paths.css.main)
.pipe(plumber(plumberOpts))
.pipe(gulpif(path.extname(paths.css.main) == '.styl', stylus()))
.pipe(gulpif(path.extname(paths.css.main) == '.scss', sass()))
.pipe(autoprefix())
.pipe(gulp.dest(paths.output))
.pipe(minify())
.pipe(rename('style.min.css'))
.pipe(gulp.dest(paths.output))
return stream
})
gulp.task('watch', ['css'], function() {
gulp.watch(paths.css.files, ['css'])
})
gulp.task('default', ['css'], function() {
console.log('Ready to go');
})
{
"name": "gulp-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "Nick Sheffield <[email protected]> (http://nicksheffield.me/)",
"license": "MIT",
"dependencies": {
"gulp": "^3.9.1",
"gulp-autoprefixer": "^3.1.1",
"gulp-clean-css": "^2.0.12",
"gulp-if": "^2.0.1",
"gulp-notify": "^2.2.0",
"gulp-plumber": "^1.1.0",
"gulp-rename": "^1.2.2",
"gulp-sass": "^2.3.2",
"gulp-stylus": "^2.5.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment