Created
May 9, 2014 11:38
-
-
Save silentworks/4b94a3e02306c0b05a58 to your computer and use it in GitHub Desktop.
Gulp with connect and livereload
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'); | |
var connect = require('connect'); | |
var livereload = require('gulp-livereload'); | |
var shell = require('gulp-shell'); | |
var sass = require('gulp-sass'); | |
var env = process.env.NODE_ENV || 'development'; | |
var port = process.env.PORT || 9008; | |
var paths = { | |
scss: 'scss/**/*.scss', | |
icons: 'img/icons/**/*.png' | |
} | |
gulp.task('server', function (next) { | |
connect().use(connect.static(__dirname)).listen(port, next); | |
}); | |
/* Sprite task */ | |
gulp.task('sprite:icons', shell.task('glue img/icons img/sprites --no-css --scss')); | |
gulp.task('sprite', function () { | |
return gulp.src('', {read:false}) | |
.pipe(shell('glue img/icons img/sprites --no-css --scss')); | |
}) | |
gulp.task('sass', ['sprite'], function () { | |
var config = { | |
includePaths: ['bower_components/foundation/scss'] | |
}; | |
if (env === 'development') { | |
} | |
if (env === 'production') { | |
config.outputStyle = 'compressed'; | |
} | |
return gulp.src('scss/app.scss') | |
.pipe(sass(config)) | |
.pipe(gulp.dest('css')) | |
.pipe(livereload()); | |
}); | |
gulp.task('watch', function () { | |
var path = require('path'); | |
/* watch html */ | |
gulp.watch('*.html').on('change', function(file) { | |
console.log('File changed: ' + path.relative('.', file.path)); | |
livereload().changed(file.path); | |
}); | |
/* watch scss */ | |
gulp.watch(paths.scss, ['sass']); | |
/* watch sprite */ | |
gulp.watch(paths.icons, ['sprite']); | |
}); | |
gulp.task('build', ['sass']); | |
gulp.task('serve', ['server', 'watch']); | |
gulp.task('default', ['build', 'sprite', 'server', 'watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment