Created
March 1, 2017 03:23
-
-
Save nicholasdixon/8b53b7df89896bf520328530c94421a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'), | |
gutil = require('gulp-util'), | |
coffee = require('gulp-coffee'), | |
browserify = require('gulp-browserify'), | |
compass = require('gulp-compass'), | |
connect = require('gulp-connect'), | |
gulpif = require('gulp-if'), | |
uglify = require('gulp-uglify'), | |
minifyHTML = require('gulp-minify-html'), | |
concat = require('gulp-concat'); | |
var env, | |
coffeeSources, | |
jsSources, | |
sassSources, | |
htmlSources, | |
jsonSources, | |
outputDir, | |
sassStyle; | |
env = process.env.NODE_ENV || 'development'; | |
if (env==='development') { | |
outputDir = 'builds/development/'; | |
sassStyle = 'expanded'; | |
} else { | |
outputDir = 'builds/production/'; | |
sassStyle = 'compressed'; | |
} | |
coffeeSources = ['components/coffee/tagline.coffee']; | |
jsSources = [ | |
'components/scripts/rclick.js', | |
'components/scripts/pixgrid.js', | |
'components/scripts/tagline.js', | |
'components/scripts/template.js' | |
]; | |
sassSources = ['components/sass/style.scss']; | |
htmlSources = [outputDir + '*.html']; | |
jsonSources = [outputDir + 'js/*.json']; | |
gulp.task('coffee', function() { | |
gulp.src(coffeeSources) | |
.pipe(coffee({ bare: true }) | |
.on('error', gutil.log)) | |
.pipe(gulp.dest('components/scripts')) | |
}); | |
gulp.task('js', function() { | |
gulp.src(jsSources) | |
.pipe(concat('script.js')) | |
.pipe(browserify()) | |
.pipe(gulpif(env === 'production', uglify())) | |
.pipe(gulp.dest(outputDir + 'js')) | |
.pipe(connect.reload()) | |
}); | |
gulp.task('compass', function() { | |
gulp.src(sassSources) | |
.pipe(compass({ | |
sass: 'components/sass', | |
image: outputDir + 'images', | |
style: sassStyle | |
}) | |
.on('error', gutil.log)) | |
.pipe(gulp.dest(outputDir + 'css')) | |
.pipe(connect.reload()) | |
}); | |
gulp.task('watch', function() { | |
gulp.watch(coffeeSources, ['coffee']); | |
gulp.watch(jsSources, ['js']); | |
gulp.watch('components/sass/*.scss', ['compass']); | |
gulp.watch('builds/development/*.html', ['html']); | |
gulp.watch(jsonSources, ['json']); | |
}); | |
gulp.task('connect', function() { | |
connect.server({ | |
root: outputDir, | |
livereload: true | |
}); | |
}); | |
gulp.task('html', function() { | |
gulp.src('builds/development/*.html') | |
.pipe(gulpif(env === 'production', minifyHTML())) | |
.pipe(gulpif(env === 'production', gulp.dest(outputDir))) | |
.pipe(connect.reload()) | |
}); | |
gulp.task('json', function() { | |
gulp.src(jsonSources) | |
.pipe(connect.reload()) | |
}); | |
gulp.task('default', ['html', 'json', 'coffee', 'js', 'compass', 'connect', 'watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment