Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A sample gulp file to using in many projects
var gulp = require('gulp'),
pkg = require('./package.json'),
path = require('path'),
connect = require('connect'),
http = require('http'),
open = require('open'),
compass = require('gulp-compass'),
refresh = require('gulp-livereload'),
tinylr = require('tiny-lr'),
livereload = tinylr(),
settings = {
livereloadPort: 35729,
serverPort: 9000,
path: {
app: './src',
css: './src/css',
sass: './src/sass',
images: './src/images',
javascript: './src/javascript',
fonts: './src/fonts'
}
};
gulp.task('html', function (){
gulp
.src(settings.path.app + '/*.html')
.pipe(refresh(livereload));
});
gulp.task('compass', function () {
gulp
.src(settings.path.app + '/**/*.{scss, sass}')
.pipe(compass({
style: 'compact',
relative: true,
css: settings.path.css,
sass: settings.path.sass,
javacript: settings.path.javascript,
font: settings.path.font
}))
.pipe(refresh(livereload));
});
gulp.task('connect-livereload', function () {
var middleware = [
require('connect-livereload')({ port: settings.livereloadPort }),
connect.static(settings.path.app),
connect.directory(settings.path.app)
],
app = connect.apply(null, middleware),
server = http.createServer(app);
server
.listen(settings.serverPort)
.on('listening', function() {
console.log('Started connect web server on http://localhost:' + settings.serverPort + '.');
open('http://localhost:' + settings.serverPort);
});
});
gulp.task('tinylr', function(){
livereload.listen(settings.livereloadPort, function(err){
if (err) return console.log(err);
});
});
gulp.task('server', function(){
gulp.run('compass', 'connect-livereload', 'tinylr');
gulp.watch([settings.path.sass + '/**/*.scss'], function(){
gulp.run('compass');
});
gulp.watch([settings.path.app + '/*.html'], function(){
gulp.run('html');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.