Skip to content

Instantly share code, notes, and snippets.

@johno
Created November 6, 2014 17:55
Show Gist options
  • Save johno/8daa5fea93c564af8a50 to your computer and use it in GitHub Desktop.
Save johno/8daa5fea93c564af8a50 to your computer and use it in GitHub Desktop.
Example SCSS preprocessing with autoprefixer and minification.

This requires a few dependencies:

  • npm
  • gulp
  • autoprefixer
  • ruby-sass

Installation

Install npm.

npm i -g gulp
npm i .

Usage

gulp
* {
box-sizing: border-box;
}
* {
box-sizing: border-box;
}
* {
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
*{box-sizing: border-box;-moz-box-sizing: border-box;-webkit-box-sizing: border-box;}
var gulp = require('gulp');
var sass = require('gulp-sass');
var rename = require('gulp-rename');
var cssmin = require('gulp-minify-css');
var prefix = require('gulp-autoprefixer');
var size = require('gulp-size');
gulp.task('scss', function() {
return gulp.src('scss/all.scss')
.pipe(sass())
.pipe(size({ gzip: true, showFiles: true }))
.pipe(renam('c-unprefixed.css')) // If you also wanted an unprefixed css file.
.pipe(gulp.dest('css'))
.pipe(prefix("last 2 versions", "> 1%", "ie 9"))
.pipe(rename('c.css'))
.pipe(gulp.dest('css'))
.pipe(cssmin())
.pipe(size({ gzip: true, showFiles: true }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('css'));
});
gulp.task('watch', function() {
gulp.watch('scss/*.scss', ['scss']);
});
gulp.task('default', ['scss', 'watch']);
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>{% if page.title %}{{ page.title }} &#8211; {% endif %}{{ site.title }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="{% if page.summary %}{{ page.summary }}{% else %}{{ site.description }}{% endif %}">
<meta name="author" content="{{ site.author }}">
{% if page.categories %}<meta name="keywords" content="{{ page.categories | join: ', ' }}">{% endif %}
<link rel="canonical" href="{{ page.url | replace:'index.html','' | prepend: site.baseurl | prepend: site.url }}">
<link rel="stylesheet" href="{{ "/css/c.min.css" | prepend: site.baseurl }}" type="text/css">
</head>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment