Created
February 20, 2017 18:42
-
-
Save waako/0851e9dd00ef9e1da98313397bcbfcc7 to your computer and use it in GitHub Desktop.
Build Script for SideCarMT.com
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 fs = require('fs'); | |
var del = require('del'); | |
var htmlreplace = require('gulp-html-replace'); | |
var uglify = require('gulp-uglify'); | |
var minifyHTML = require('gulp-minify-html'); | |
var minifyCSS = require('gulp-minify-css'); | |
var rename = require("gulp-rename"); | |
var bowerSrc = require('gulp-bower-src'); | |
var gulpFilter = require('gulp-filter'); | |
var concat = require('gulp-concat'); | |
var uncss = require('gulp-uncss'); | |
var imagemin = require('gulp-imagemin'); | |
var jpegtran = require('imagemin-jpegtran'); | |
var svgo = require('imagemin-svgo'); | |
var gutil = require('gulp-util'); | |
var filter = gulpFilter('**/*.js', '!**/*.min.js'); | |
gulp.task('clean', function (cb) { | |
return del(['./build/**'], cb) | |
}); | |
gulp.task('minify-html', ['htmlreplace'], function() { | |
var opts = { | |
}; | |
return gulp.src('./build/*.html') | |
.pipe(minifyHTML(opts)) | |
.pipe(rename(function(path){ | |
path.basename = path.basename.replace('-pre', ''); | |
path.ext = '.html'; | |
})) | |
.pipe(gulp.dest('build/')); | |
}); | |
gulp.task('minify-css', ['clean'], function() { | |
return gulp.src('./scss/*.css') | |
.pipe(uncss({ | |
html: ['./*.html'], | |
ignore: [/^meta.foundation/, /f-topbar-fixed/, /contain-to-grid/, /sticky/, /fixed/, /nth-child/], | |
}).on('error', gutil.log)) | |
.pipe(minifyCSS().on('error', gutil.log)) | |
.pipe(rename('styles.min.css').on('error', gutil.log)) | |
.pipe(gulp.dest('./build/css/')) | |
}); | |
gulp.task('minify-images', ['move-assets'], function () { | |
return gulp.src('./build/assets/**/*') | |
.pipe(imagemin({ | |
progressive: true, | |
use: [jpegtran(), svgo()] | |
})) | |
.pipe(gulp.dest('./build/assets')); | |
}); | |
gulp.task('move-assets', ['htmlreplace'], function() { | |
return gulp.src('./assets/**/*') | |
.pipe(gulp.dest('./build/assets')) | |
}); | |
gulp.task('bower', ['htmlreplace'], function () { | |
return bowerSrc() | |
.pipe(filter) | |
.pipe(uglify().on('error', gutil.log)) | |
.pipe(filter.restore()) | |
.pipe(gulp.dest('build/js')); | |
}); | |
gulp.task('bundle', ['bower'], function () { | |
return gulp.src(['./build/js/jquery/dist/jquery.min.js', './build/js/foundation/js/foundation/foundation.js', './build/js/foundation/js/foundation/foundation.equalizer.js', './build/js/foundation/js/foundation/foundation.topbar.js', './js/app.js']) | |
.pipe(concat('bundle.min.js')) | |
.pipe(uglify().on('error', gutil.log)) | |
.pipe(gulp.dest('build/js')); | |
}); | |
gulp.task('htmlreplace', ['minify-css'], function() { | |
return gulp.src('*.html') | |
.pipe(htmlreplace({ | |
//'css': './css/styles.min.css', | |
'css': '', | |
'js': './js/bundle.min.js', | |
'modernizr': { | |
src: ['./js/modernizr/modernizr.js'], | |
tpl: '<script async src="%s"></script>' | |
}, | |
'inline': '<style>' + fs.readFileSync('./build/css/styles.min.css') + '</style>' | |
})) | |
.pipe(rename(function(path){ | |
path.suffix = "-pre", | |
path.extname = '.html'; | |
})) | |
.pipe(gulp.dest('build/')); | |
}); | |
gulp.task('build', ['clean', 'minify-css', 'htmlreplace', 'minify-html', 'move-assets', 'minify-images', 'bower', 'bundle']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment