Skip to content

Instantly share code, notes, and snippets.

@norcal82
Created May 7, 2015 16:13
Show Gist options
  • Save norcal82/5c7f366fa23690d45ef0 to your computer and use it in GitHub Desktop.
Save norcal82/5c7f366fa23690d45ef0 to your computer and use it in GitHub Desktop.
gulpfile.coffee
###******************************************************************************
1. DEPENDENCIES
******************************************************************************
###
'use strict'
gulp = require('gulp')
jade = require('gulp-jade')
minifyHTML = require('gulp-minify-html')
sass = require('gulp-sass')
minifycss = require('gulp-minify-css')
autoprefixer = require('gulp-autoprefixer')
jshint = require('gulp-jshint')
uglify = require('gulp-uglify')
stylish = require('jshint-stylish')
rename = require('gulp-rename')
concat = require('gulp-concat')
notify = require('gulp-notify')
plumber = require('gulp-plumber')
size = require('gulp-size')
browserSync = require('browser-sync')
reload = browserSync.reload
###******************************************************************************
2. FILE DESTINATIONS (RELATIVE TO ASSSETS FOLDER)
******************************************************************************
###
target =
template_src: 'templates/*.jade'
sass_src: 'scss/**/*.scss'
css_dest: 'css'
js_lint_src: [
'js/main.js'
'js/something.js'
]
js_uglify_src: [ '' ]
js_concat_src: [
'js/main.js'
'js/something.js'
]
js_dest: 'js'
###******************************************************************************
3. MINIFY HTML
******************************************************************************
###
gulp.task 'minify-html', ->
opts =
comments: false
spare: true
gulp.src('./*.html').pipe(minifyHTML(opts)).pipe gulp.dest('html')
return
###******************************************************************************
3. SASS TASK
******************************************************************************
###
gulp.task 'sass', ->
gulp.src(target.sass_src).pipe(plumber()).pipe(sass()).pipe(autoprefixer('last 2 version', '> 1%', 'ie 8', 'ie 9', 'ios 6', 'android 4')).pipe(minifycss()).pipe(concat('main.css')).pipe(gulp.dest(target.css_dest)).pipe reload(stream: true)
# .pipe(notify({message: 'SCSS processed!'})); // notify when done
return
###******************************************************************************
4. JS TASKS
******************************************************************************
###
# lint my custom js
gulp.task 'js-lint', ->
gulp.src(target.js_lint_src).pipe(jshint()).pipe jshint.reporter(stylish)
# present the results in a beautiful way
return
# minify all js files that should not be concatinated
gulp.task 'js-uglify', ->
gulp.src(target.js_uglify_src).pipe(uglify()).pipe(rename((dir, base, ext) ->
# give the files a min suffix
trunc = base.split('.')[0]
trunc + '.min' + ext
)).pipe gulp.dest(target.js_dest)
# where to put the files
# .pipe(notify({ message: 'JS uglified'})); // notify when done
return
# minify & concatinate all other js
gulp.task 'js-concat', ->
gulp.src(target.js_concat_src).pipe(uglify()).pipe(concat('main.min.js')).pipe gulp.dest(target.js_dest)
# where to put the files
# .pipe(notify({message: 'JS concatinated'})); // notify when done
return
###******************************************************************************
3. BROWSER SYNC
******************************************************************************
###
# Static server
gulp.task 'browser-sync', ->
browserSync server: baseDir: './'
return
###******************************************************************************
3. JADE TO HTML
******************************************************************************
###
gulp.task 'templates', ->
gulp.src('templates/index.jade').pipe(plumber()).pipe(jade(pretty: true)).pipe(gulp.dest('../dev/')).pipe reload(stream: true)
return
###******************************************************************************
3. PRINT FILESIZES
******************************************************************************
###
#gulp.task('stats', function () {
# var s = size();
# return gulp.src('../dev/**/*')
# .pipe(s)
# .pipe(gulp.dest('../dev'))
# .pipe(notify({
# message: 'all files ' + s.prettySize
# }));
#});
# Default task to be run with `gulp`
gulp.task 'default', [
'templates'
'browser-sync'
'sass'
], ->
gulp.watch target.template_src, [
'templates'
'minify-html'
]
gulp.watch target.sass_src, [ 'sass' ]
gulp.watch target.js_lint_src, [ 'js-lint' ]
gulp.watch target.js_minify_src, [ 'js-uglify' ]
gulp.watch target.js_concat_src, [ 'js-concat' ]
return
# ---
# generated by js2coffee 2.0.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment