minify plugin

This commit is contained in:
bchiang7
2016-12-09 21:17:44 -05:00
parent 380a86c6dc
commit f33979af1c
10 changed files with 1972 additions and 43 deletions

View File

@@ -1,14 +1,10 @@
var gulp = require('gulp');
var browserSync = require('browser-sync');
var cp = require('child_process');
var htmlmin = require('gulp-htmlmin');
var sass = require('gulp-sass');
var cssnano = require('gulp-cssnano');
var cleanCSS = require('gulp-clean-css');
var prefix = require('gulp-autoprefixer');
var jshint = require('gulp-jshint');
var babel = require('gulp-babel');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var jekyll = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll';
@@ -38,22 +34,14 @@ gulp.task('browser-sync', ['styles', 'scripts', 'jekyll-dev'], function() {
});
});
gulp.task('htmlmin', function() {
return gulp.src('*.html')
.pipe(htmlmin({collapseWhitespace: true, removeComments: true}))
.pipe(gulp.dest('_site'));
});
// Compile files from _scss into both _site/css (for live injecting) and site (for future jekyll builds)
gulp.task('styles', function() {
return gulp.src('_scss/*.scss')
.pipe(sass({
includePaths: ['scss'],
onError: browserSync.notify
})
)
}))
.pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], {cascade: true}))
.pipe(cssnano())
.pipe(gulp.dest('_site/css'))
.pipe(browserSync.reload({stream:true}))
.pipe(gulp.dest('css'));
@@ -78,6 +66,8 @@ gulp.task('watch', function () {
gulp.watch(['index.html', '404.html', '_layouts/*.html', '_posts/*', '_includes/*.html', '_drafts/*', '**/*.html'], ['jekyll-rebuild']);
});
// ============================= PROD ============================== //
// Build the Jekyll Site in production mode
gulp.task('jekyll-prod', function (done) {
browserSync.notify(messages.jekyllProd);
@@ -85,23 +75,19 @@ gulp.task('jekyll-prod', function (done) {
.on('close', done);
});
// Identical Sass compilation task to development mode, with an additional minification step thrown in using clean-css
gulp.task('styles-prod', function () {
return gulp.src('_scss/*.scss')
.pipe(sass({
includePaths: ['scss'],
onError: browserSync.notify
}))
.pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
.pipe(cssnano())
.pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], {cascade: true}))
.pipe(gulp.dest('_site/css'))
.pipe(gulp.dest('css'));
});
// Identical Javascript compilation task to development mode, with an additional minification step thrown in using uglify
gulp.task('scripts-prod', function() {
return gulp.src(['js/*.js'])
.pipe(uglify())
.pipe(gulp.dest('_site/js'));
});
@@ -120,4 +106,4 @@ gulp.task('fonts', function() {
gulp.task('default', ['browser-sync', 'watch']);
// Build task, run using gulp build to compile Sass and Javascript ready for deployment.
gulp.task('build', ['fonts', 'images', 'styles-prod', 'scripts-prod', 'jekyll-prod']);
gulp.task('build', ['styles-prod', 'scripts-prod', 'images', 'fonts', 'jekyll-prod']);