Skip to content

Instantly share code, notes, and snippets.

@cullylarson
Last active December 9, 2015 00:54
Show Gist options
  • Save cullylarson/712347631cc9a8bf1eb4 to your computer and use it in GitHub Desktop.
Save cullylarson/712347631cc9a8bf1eb4 to your computer and use it in GitHub Desktop.
Gulpfile snippet for SASS and Bootstrap
"use strict"
require("babel-polyfill")
const argv = require('minimist')(process.argv.slice(2))
import gulp from 'gulp'
import gutil from 'gulp-util'
import sass from 'gulp-sass'
import concat from 'gulp-concat'
import gulpif from 'gulp-if'
import autoprefixer from 'gulp-autoprefixer'
import sourcemaps from 'gulp-sourcemaps'
import minifyCss from 'gulp-minify-css'
import os from 'os'
import batch from 'gulp-batch'
import plumber from 'gulp-plumber'
const plumberh = function (err) {
gutil.beep()
console.log(err)
this.emit('end')
}
const config = {
bootstrap: "./node_modules/bootstrap-sass",
scss: "src/style/**/*.scss",
}
const enabled = {
// disable source maps when `--production`
maps: !argv.production,
}
gulp.task('style', () => {
return gulp.src(config.scss)
.pipe(plumber({errorHandler: plumberh}))
.pipe(gulpif(enabled.maps, sourcemaps.init()))
.pipe(sass({includePaths: [config.bootstrap + '/assets/stylesheets']}).on('error', sass.logError))
.pipe(concat("main.css"))
.pipe(autoprefixer({
browsers: [
'last 2 versions',
'ie 8',
'ie 9',
'android 2.3',
'android 4',
'opera 12'
]
}))
.pipe(minifyCss({
advanced: false,
rebase: false
}))
.pipe(gulpif(enabled.maps, sourcemaps.write(".")))
.pipe(gulp.dest('dist/style'))
})
gulp.task('watch', () => {
gulp.watch([config.scss], batch((events, done) => {
gulp.start('style', done)
}))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment