|
var gulp = require('gulp'), |
|
clean = require('gulp-clean'), |
|
jshint = require('gulp-jshint'), |
|
usemin = require('gulp-usemin'), |
|
minifyJS = require('gulp-uglify'), |
|
minifyCSS = require('gulp-minify-css'), |
|
rev = require('gulp-rev'), |
|
runSequence = require('run-sequence'), |
|
connect = require('gulp-connect'); |
|
|
|
/** |
|
* Paths |
|
*/ |
|
var paths = { |
|
js: './src/assets/js/**/*.js', |
|
css: './src/assets/css/**/*.css', |
|
images: './src/assets/images/**.*', |
|
index: './src/index.html', |
|
pages: './src/pages/**.*', |
|
api: './src/api/**.*', |
|
dist: './dist', |
|
}; |
|
|
|
/** |
|
* JSHint - Check for JS errors |
|
*/ |
|
gulp.task('jshint', function() { |
|
return gulp.src(paths.js) |
|
.pipe(jshint()) |
|
.pipe(jshint.reporter('default')); |
|
}); |
|
|
|
/** |
|
* Clean - Clean out dist directory |
|
*/ |
|
gulp.task('clean', function () { |
|
return gulp.src(paths.dist, {read: false}) |
|
.pipe(clean()); |
|
}); |
|
|
|
/** |
|
* Copy some files to dist |
|
*/ |
|
gulp.task('copy', ['copy-pages', 'copy-api', 'copy-images']); |
|
|
|
gulp.task('copy-pages', function() { |
|
return gulp.src(paths.pages) |
|
.pipe(gulp.dest(paths.dist + '/pages')); |
|
}); |
|
gulp.task('copy-api', function() { |
|
return gulp.src(paths.api) |
|
.pipe(gulp.dest(paths.dist + '/api')); |
|
}); |
|
gulp.task('copy-images', function() { |
|
return gulp.src(paths.images) |
|
.pipe(gulp.dest(paths.dist + '/images')); |
|
}); |
|
|
|
/** |
|
* Minify all files into one and link this in our distribution output |
|
*/ |
|
gulp.task('usemin', ['usemin-css', 'usemin-js']); |
|
|
|
gulp.task('usemin-css', function() { |
|
return gulp.src(paths.index) |
|
.pipe(usemin({ |
|
css: [minifyCSS(), rev(), 'concat'] |
|
})) |
|
.pipe(gulp.dest(paths.dist)); |
|
}); |
|
gulp.task('usemin-js', function() { |
|
return gulp.src(paths.index) |
|
.pipe(usemin({ |
|
js: [minifyJS(), rev(), 'concat'] |
|
})) |
|
.pipe(gulp.dest(paths.dist)); |
|
}); |
|
|
|
/** |
|
* Watch for file chnages, and carry out a task. Then reload the page. |
|
*/ |
|
gulp.task('watch', function () { |
|
gulp.watch([paths.css], ['usemin-css']); |
|
gulp.watch([paths.js], ['usemin-js']); |
|
gulp.watch([paths.pages], ['copy-pages']); |
|
gulp.watch([paths.api], ['copy-api']); |
|
gulp.watch([paths.images], ['copy-images']); |
|
connect.reload(); |
|
}); |
|
|
|
/** |
|
* Create a local live reload server |
|
*/ |
|
gulp.task('connect', function() { |
|
connect.server({ |
|
root: paths.dist, |
|
port: 8080, |
|
livereload: true |
|
}); |
|
}); |
|
|
|
/** |
|
* `gulp` task |
|
*/ |
|
gulp.task('default', function() { |
|
runSequence('jshint', 'clean', 'copy', 'usemin'); |
|
}); |
|
|
|
/** |
|
* `gulp dev` task |
|
*/ |
|
gulp.task('dev', ['connect', 'watch']); |