Created
August 15, 2014 00:10
-
-
Save EduardoLopes/d7efbf97114164d9a4f4 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'); | |
var concat = require('gulp-concat'); | |
var uglify = require('gulp-uglify'); | |
var del = require('del'); | |
var htmlmin = require('gulp-htmlmin'); | |
var smoosher = require('gulp-smoosher'); | |
var cssmin = require('gulp-cssmin'); | |
var es = require('event-stream'); | |
var htmlbuild = require('gulp-htmlbuild'); | |
var runSequence = require('run-sequence'); | |
var imagemin = require('gulp-imagemin'); | |
var livereload = require('gulp-livereload'); | |
var gulpSrc = function (opts) { | |
var paths = es.through(); | |
var files = es.through(); | |
paths.pipe(es.writeArray(function (err, srcs) { | |
gulp.src(srcs, { cwd: 'app' }).pipe(files); | |
})); | |
return es.duplex(paths, files); | |
}; | |
var jsBuild = es.pipeline( | |
concat('min.js'), | |
uglify(), | |
gulp.dest('./dist') | |
); | |
var cssBuild = es.pipeline( | |
concat('min.css'), | |
cssmin(), | |
gulp.dest('./dist') | |
); | |
gulp.task('index', function(cb) { | |
del(['./dist/*'], cb); | |
gulp.src(['./app/index.html']) | |
.pipe(htmlbuild({ | |
// build js with preprocessor | |
js: htmlbuild.preprocess.js(function (block) { | |
block.pipe(gulpSrc()) | |
.pipe(jsBuild); | |
block.end('min.js'); | |
}), | |
// build css with preprocessor | |
css: htmlbuild.preprocess.css(function (block) { | |
block.pipe(gulpSrc()) | |
.pipe(cssBuild); | |
block.end('min.css'); | |
}), | |
remove: function (block) { | |
block.end(); | |
} | |
})) | |
.pipe(gulp.dest('./dist')); | |
}); | |
gulp.task('smoosher', function (cb) { | |
return gulp.src('./dist/index.html') | |
.pipe(smoosher()) | |
.pipe(htmlmin({ | |
collapseWhitespace: true, | |
removeAttributeQuotes: true, | |
removeComments: true, | |
})) | |
.pipe(gulp.dest('./dist')); | |
}); | |
gulp.task('images', function () { | |
return gulp.src('app/images/*.{png,jpg}') | |
.pipe(imagemin({ | |
progressive: true, | |
svgoPlugins: [{removeViewBox: false}], | |
})) | |
.pipe(gulp.dest('./dist')); | |
}); | |
gulp.task('clean', function(cb) { | |
del(['./dist/min.css', './dist/min.js'], cb); | |
}); | |
gulp.task('default', function () { | |
runSequence('index', 'images', 'smoosher', 'clean'); | |
}); | |
gulp.task('watch', function() { | |
// Create LiveReload server | |
livereload.listen(); | |
// Watch any files in dist/, reload on change | |
gulp.watch(['app/**']).on('change', livereload.changed); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment