Skip to content

Instantly share code, notes, and snippets.

@isaacdanielanderson
Created October 27, 2017 23:05
Show Gist options
  • Save isaacdanielanderson/ea29f26059765f09d3def802506ad02f to your computer and use it in GitHub Desktop.
Save isaacdanielanderson/ea29f26059765f09d3def802506ad02f to your computer and use it in GitHub Desktop.
var gulp = require('gulp');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var input = './styles/**/*.scss';
var output = './styles/';
// SASS options
var sassOptions = {
errLogToConsole: true,
outputStyle: 'compressed'
};
// Autoprefixer options
var autoprefixerOptions = {
browsers: ['last 2 versions', '> 5%', 'Firefox ESR']
};
gulp.task('sass', function () {
return gulp
.src(input)
.pipe(sourcemaps.init()) // Sourcemaps are for viewing where styles are located in the inspector tool
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(autoprefixer(autoprefixerOptions))
.pipe(gulp.dest(output));
});
gulp.task('watch', function() {
return gulp
// Watch the input folder for change,
// and run `sass` task when something happens
.watch(input, ['sass'])
// When there is a change,
// log a message in the console
.on('change', function(event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});
});
gulp.task('default', ['sass', 'watch' /*, possible other tasks... */]);
// Courtesy of Hugo: https://www.sitepoint.com/simple-gulpy-workflow-sass/ Thanks!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment