Created
December 27, 2015 20:45
-
-
Save duaneleem/9adc4fc32e94076ced93 to your computer and use it in GitHub Desktop.
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'), | |
minifycss = require('gulp-minify-css'), | |
jshint = require('gulp-jshint'), | |
stylish = require('jshint-stylish'), | |
uglify = require('gulp-uglify'), | |
usemin = require('gulp-usemin'), | |
imagemin = require('gulp-imagemin'), | |
rename = require('gulp-rename'), | |
concat = require('gulp-concat'), | |
notify = require('gulp-notify'), | |
cache = require('gulp-cache'), | |
changed = require('gulp-changed'), | |
rev = require('gulp-rev'), | |
browserSync = require('browser-sync'), | |
ngannotate = require('gulp-ng-annotate'), | |
del = require('del'); | |
gulp.task('jshint', function() { | |
return gulp.src('app/scripts/**/*.js') | |
.pipe(jshint()) | |
.pipe(jshint.reporter(stylish)); | |
}); | |
gulp.task('usemin', ['jshint'], function() { | |
// return gulp.src('./app/menu.html') | |
return gulp.src('./app/*.html') | |
.pipe(usemin({ | |
css: [minifycss(), rev()], | |
js: [ngannotate(), uglify(), rev()] | |
})) | |
.pipe(gulp.dest('dist/')); | |
}); | |
// Images | |
gulp.task('imagemin', function() { | |
return del(['dist/images']), gulp.src('app/images/**/*') | |
.pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))) | |
.pipe(gulp.dest('dist/images')) | |
.pipe(notify({ message: 'Images task complete' })); | |
}); | |
// Clean | |
gulp.task('clean', function() { | |
return del(['dist']); | |
}); | |
gulp.task('copyfonts', ['clean'], function() { | |
gulp.src('./bower_components/font-awesome/fonts/**/*.{ttf,woff,eof,svg}*') | |
.pipe(gulp.dest('./dist/fonts')); | |
gulp.src('./bower_components/bootstrap/dist/fonts/**/*.{ttf,woff,eof,svg}*') | |
.pipe(gulp.dest('./dist/fonts')); | |
}); | |
// Watch | |
gulp.task('watch', ['browser-sync'], function() { | |
// Watch .js files | |
gulp.watch('{app/scripts/**/*.js,app/styles/**/*.css,app/**/*.html}', ['usemin']); | |
// Watch image files | |
gulp.watch('app/images/**/*', ['imagemin']); | |
}); | |
gulp.task('browser-sync', ['default'], function () { | |
var files = [ | |
'app/**/*.html', | |
'app/styles/**/*.css', | |
'app/images/**/*.png', | |
'app/scripts/**/*.js', | |
'dist/**/*' | |
]; | |
// browserSync.init(files, { | |
// server: { | |
// baseDir: "dist", | |
// index: "menu.html" | |
// } | |
// }); | |
browserSync.init(files, { | |
server: { | |
baseDir: 'dist', | |
index: 'index.html' | |
}, | |
reloadDelay: 1000 | |
}); | |
// Watch any files in dist/, reload on change | |
gulp.watch(['dist/**']).on('change', browserSync.reload); | |
}); | |
// copy views to dist folder. | |
gulp.task("copyviews", function() { | |
gulp.src("app/views/*") | |
.pipe(gulp.dest("dist/views")); | |
}) | |
// Default task | |
gulp.task('default', ['clean'], function() { | |
gulp.start('usemin', 'imagemin','copyfonts', 'copyviews'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample gulp.js configuration.