Created
June 26, 2016 12:06
-
-
Save mexiter/1cda7041b57dc856ffdcbb479897171d to your computer and use it in GitHub Desktop.
gulp_environments and minifies fron lynda
This file contains hidden or 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'), | |
jsonminify = require('gulp-jsonminify'), | |
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('builds/development/js/*.json', ['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('builds/development/js/*.json') | |
.pipe(gulpif(env === 'production', jsonminify())) | |
.pipe(gulpif(env === 'production', gulp.dest('builds/production/js'))) | |
.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