Skip to content

Instantly share code, notes, and snippets.

@gustavoquinalha
Last active April 27, 2017 17:07
Show Gist options
  • Save gustavoquinalha/82cbd1a03bd73ad270bbef59509615a2 to your computer and use it in GitHub Desktop.
Save gustavoquinalha/82cbd1a03bd73ad270bbef59509615a2 to your computer and use it in GitHub Desktop.
const gulp = require('gulp');
const imagemin = require('gulp-imagemin');
const uncss = require('gulp-uncss');
const rename = require('gulp-rename');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const cleanCSS = require('gulp-clean-css');
const browserSync = require('browser-sync').create();
const zip = require('gulp-zip');
const responsive = require('gulp-responsive');
const load = require('gulp-load-plugins')();
const pageres = require('pageres');
const htmlmin = require('gulp-htmlmin');
const autoprefixer = require('gulp-autoprefixer');
gulp.task('minify-css', function() {
return gulp.src('css/master.min.css')
.pipe(cleanCSS({debug: true}, function(details) {
console.log(details.name + ': ' + details.stats.originalSize);
console.log(details.name + ': ' + details.stats.minifiedSize);
}))
.pipe(rename('final.css'))
.pipe(gulp.dest('css'));
});
// autoprefix
gulp.task('prefix', () =>
gulp.src('css/all.css')
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulp.dest('css/test'))
);
// autoprefix
// minify html
gulp.task('html-min', function() {
return gulp.src('./*.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(rename('teste.html'))
.pipe(gulp.dest('./'));
});
// minify html
// SCREENSHOT
gulp.task('pg', function(){
const pageres = new pageres({delay: 2})
.src('index.html', ['480x320', '1024x768', 'iphone 5s'])
.dest('prints')
.run()
.then(() => console.log('done'));
});
// SCREENSHOT
// RESIZE IMAGES
gulp.task('resize-img', function () {
return gulp.src('img/*.{jpg,png}')
.pipe(load.responsive({
'*.jpg': [{
width: 100,
rename: {
suffix: '-thumb',
}
}, {
width: 300,
rename: {
suffix: '-medium',
// extname: '.jpg',
},
}, {
width: 900,
rename: {
suffix: '-big',
},
// Do not enlarge the output image if the input image are already less than the required dimensions.
withoutEnlargement: true,
}],
'*.png': [{
width: 100,
rename: {
suffix: '-thumb',
}
}, {
width: 300,
rename: {
suffix: '-medium',
// extname: '.jpg',
},
}, {
width: 900,
rename: {
suffix: '-big',
},
// Do not enlarge the output image if the input image are already less than the required dimensions.
withoutEnlargement: true,
}]
}, {
// Global configuration for all images
// The output quality for JPEG, WebP and TIFF output formats
quality: 70,
// Use progressive (interlace) scan for JPEG and PNG output
progressive: true,
// Strip all metadata
withMetadata: false,
// Do not emit the error when image is enlarged.
errorOnEnlargement: false,
}))
.pipe(gulp.dest('img/dist'));
});
// RESIZE IMAGES
// ZIP-ARCHIVES
gulp.task('zip', function(){
gulp.src('./img/*')
.pipe(zip('archive.zip'))
.pipe(gulp.dest('download'))
});
//ZIP-ARCHIVES
// BROWSER-SYNC
gulp.task('browser-sy', function() {
browserSync.init({
server: {
baseDir: ''
},
})
})
// BROWSER-SYNC
// MINIFIC-IMGS
gulp.task('build-img', function(){
gulp.src('img/**/*')
.pipe(imagemin())
.pipe(gulp.dest('img'));
})
// MINIFIC-IMGS
// CONCACTENE-JS
gulp.task('build-js', function(){
gulp.src('js/*.js')
.pipe(concat('all.js'))
.pipe(gulp.dest('js/test/'))
})
// CONCACTENE-JS
//MINIFIC JS
gulp.task('minifi-js', function(){
gulp.src('js/test/all.js')
.pipe(concat('final.min.js'))
.pipe(uglify())
.pipe(gulp.dest('js'))
});
//MINIF JS
// BUILD-CSS
gulp.task('build-css', function(){
gulp.src('css/*.css')
.pipe(concat('all.css'))
.pipe(gulp.dest('css'))
});
// BUILD-CSS
// UNCSS
gulp.task('un-css', function () {
return gulp.src('css/all.css')
.pipe(uncss({
html: ['*.html'],
js: ['*.js']
}))
.pipe(rename('final-clean.css'))
.pipe(gulp.dest('css/final'))
});
// UNCSS
// TOPTOPTOP
gulp.task('css', function(){
gulp.src('css/*.css')
.pipe(uncss({
html: ['*.html'],
js: ['*.js']
}))
.pipe(cleanCSS({debug: true}, function(details) {
console.log(details.name + ': ' + details.stats.originalSize);
console.log(details.name + ': ' + details.stats.minifiedSize);
}))
.pipe(concat('master.min.css'))
.pipe(gulp.dest('css'));
});
// TOPTOPTOP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment