Starting Gulpfile
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'), | |
lp = require('gulp-load-plugins')(), // automatically load our plugins | |
_ = require('lodash'); | |
function join(p1, p2) { | |
if(_.isArray(p2)) { | |
return _.map(p2, _.partial(join, p1)); | |
} | |
return path.join(p1, p2 || ''); | |
} | |
var appPath = _.partial(join, 'app'); | |
var buildPath = _.partial(join, 'build'); | |
var config = { | |
httpPort: '9000', | |
// views | |
srcViews: appPath('views/**/*.html'), | |
destViews: buildPath('views/'), | |
srcIndex: appPath('index.html'), // this will be more useful in the future | |
// styles | |
srcStyles: appPath('styles/**/*.css'), | |
destStyles: buildPath('styles'), | |
// scripts | |
srcScripts: appPath(['scripts/*.js', 'scripts/*/*.js', 'scripts/**/*.js']) // There is reason to this madness, will explain. | |
destScripts: buildPath('scripts'), | |
// images | |
srcImages: appPath('images/**/*'), // supply extensions if you desire | |
destImages: buildPath('images'), | |
}; | |
gulp.task('styles', function () { | |
return gulp.src(config.srcStyles) | |
.pipe(lp.plumber()) | |
.pipe(lp.changed(config.destStyles)) | |
.pipe(gulp.dest(config.destStyles)) | |
.pipe(lp.connect.reload()); | |
}); | |
gulp.task('scripts', function () { | |
return gulp.src(config.srcScripts) | |
.pipe(lp.plumber()) | |
.pipe(lp.changed(config.destScripts)) | |
.pipe(gulp.dest(config.destScripts)) | |
.pipe(lp.connect.reload()); | |
}); | |
gulp.task('images', function () { | |
return gulp.src(config.srcImages) | |
.pipe(lp.plumber()) | |
.pipe(lp.changed(config.destImages)) | |
.pipe(gulp.dest(config.destImages)) | |
.pipe(lp.connect.reload()); | |
}); | |
gulp.task('views', function () { | |
return gulp.src(config.srcViews) | |
.pipe(lp.plumber()) | |
.pipe(lp.changed(config.destViews)) | |
.pipe(gulp.dest(config.destViews)) | |
.pipe(lp.connect.reload()); | |
}); | |
gulp.task('index', ['styles', 'scripts'], function () { | |
return gulp.src(config.srcIndex) | |
.pipe(lp.plumber()) | |
.pipe(gulp.dest(buildPath())) | |
.pipe(lp.connect.reload()); | |
}); | |
gulp.task('clean', function () { | |
return gulp.src(buildPath(), {read: false}) | |
.pipe(lp.clean()) | |
}); | |
gulp.task('watch', function () { | |
gulp.watch(config.srcStyles, ['styles']); | |
gulp.watch(config.srcViews, ['views']); | |
gulp.watch(config.srcImages, ['images']); | |
gulp.watch(config.srcScripts, ['scripts']); | |
gulp.watch(config.srcIndex, ['index']); | |
}); | |
gulp.task('build', ['clean'], function (cb) { | |
runSequence(['index', 'images', 'views'], cb); | |
}); | |
gulp.task('server', function () { | |
lp.connect.server({ | |
root: buildPath(), | |
port: config.httpPort, | |
livereload: true | |
}); | |
}); | |
gulp.task('default', ['build'], function (cb) { | |
runSequence('server', 'watch', cb); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment