Skip to content

Instantly share code, notes, and snippets.

@yosukehasumi
Last active July 30, 2016 07:09
Show Gist options
  • Save yosukehasumi/d21f3ed89171ea5fc234 to your computer and use it in GitHub Desktop.
Save yosukehasumi/d21f3ed89171ea5fc234 to your computer and use it in GitHub Desktop.
Gulp SCSS and CoffeeScript compiler
// var stylesheet_dir = "path/to/theme"
// modules
var gulp = require('gulp');
var gutil = require('gulp-util');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var coffee = require('gulp-coffee');
var minifyCSS = require('gulp-clean-css');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var merge2 = require('merge2');
// tasks
gulp.task('scss', function () {
gulp.src(stylesheet_dir + '/scss/style.scss')
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({ browsers: ['> 5%', 'last 2 versions'] }))
.pipe(minifyCSS({keepSpecialComments: '*', keepBreaks: false}))
.pipe(gulp.dest(stylesheet_dir + '/'));
});
gulp.task('library', function () {
gulp.src([
stylesheet_dir + '/js/library/jquery-2.1.4.min.js',
stylesheet_dir + '/js/library/*.js'
])
.pipe(concat('library.js'))
.pipe(uglify())
.pipe(gulp.dest(stylesheet_dir + '/js/'));
});
gulp.task('javascript', function () {
var includesStream = gulp.src(stylesheet_dir + '/js/library.js');
var coffeeStream = gulp.src(stylesheet_dir + '/js/coffee/master.coffee')
.pipe(coffee({bare: true}).on('error', gutil.log))
.pipe(uglify());
merge2(includesStream, coffeeStream)
.pipe(concat('site.js'))
.pipe(gulp.dest(stylesheet_dir + '/js/'));
});
// watch
gulp.task('default', function () {
gulp.watch(stylesheet_dir + '/scss/**/*.scss', ['scss']);
gulp.watch(stylesheet_dir + '/js/library/**/*.js', ['library']);
gulp.watch(stylesheet_dir + '/js/coffee/**/*.coffee', ['javascript']);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment