Skip to content

Instantly share code, notes, and snippets.

@motss
Last active May 3, 2016 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motss/db9c90fb390cdcf620396d674cc5fc00 to your computer and use it in GitHub Desktop.
Save motss/db9c90fb390cdcf620396d674cc5fc00 to your computer and use it in GitHub Desktop.
minify everything inside bower_components
var gulp = require('gulp');
var del = require('del');
var runSequence = require('run-sequence');
// var minifyHTML = require('gulp-minify-html');
var minifyInline = require('gulp-minify-inline');
var size = require('gulp-size');
var uglify = require('gulp-uglify');
var htmlmin = require('gulp-htmlmin');
var options = {
collapseWhitespace: true,
removeComments: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
removeOptionalTags: true
};
gulp.task('default', function() {
console.log('Gulp is up and running.');
runSequence(
'clean',
'minifyBowerComponents',
'uglify',
'copy'
);
});
gulp.task('minify', function() {
return gulp.src([
'*.html',
'!index.html'
]).pipe(minifyInline())
.pipe(htmlmin(options))
// .pipe(minifyHTML())
.pipe(gulp.dest('dist'));
});
gulp.task('uglify', function() {
return gulp.src([
'bower_components/**/*.js',
'!bower_components/lodash/**/*.js',
'!bower_components/webcomponentsjs/**/*.js',
'!bower_components/**/demo/**/*.js',
'!bower_components/**/test/**/*.js',
]).pipe(size({
pretty: !0,
title: 'Before uglify...'
})).pipe(uglify())
.pipe(size({
pretty: !0,
title: 'After uglify...'
}))
.pipe(size({
pretty: !0,
title: 'After uglify and minify...',
gzip: !0
}))
.pipe(gulp.dest('dist'));
});
gulp.task('copy', function() {
return gulp.src([
'bower_components/lodash/**/*.min.js',
'bower_components/webcomponentsjs/**/*.min.js',
], { base: 'bower_components' })
.pipe(size({
pretty: !0,
title: 'Before copy...',
gzip: !0
})).pipe(gulp.dest('dist'));
});
gulp.task('minifyBowerComponents', function() {
return gulp.src([
'bower_components/**/*.html',
'!bower_components/**/index.html',
'!bower_components/**/demo/**/*.html',
'!bower_components/**/test/**/*.html',
]).pipe(size({
pretty: !0,
title: 'Before minify...'
}))
.pipe(minifyInline())
.pipe(htmlmin(options))
// .pipe(minifyHTML())
.pipe(size({
pretty: !0,
title: 'After minify...'
}))
.pipe(size({
gzip: !0,
pretty: !0,
title: 'After minify and gzip...'
}))
.pipe(gulp.dest('dist'));
});
gulp.task('clean', function() {
return del([
'dist'
]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment