Created
July 27, 2017 05:23
-
-
Save marcellorg/84ea14f31fed26438ef19cea5cbf10c4 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 plumber = require('gulp-plumber'); | |
var sass = require('gulp-sass'); | |
var watch = require('gulp-watch'); | |
var concat = require('gulp-concat'); | |
var gulpif = require('gulp-if'); | |
var cssnano = require('gulp-cssnano'); | |
var imagemin = require('gulp-imagemin'); | |
var uglify = require('gulp-uglify'); | |
var rimraf = require('gulp-rimraf'); | |
var args = require('yargs') | |
.default('production', false) | |
.alias('p', 'production') | |
.argv; | |
gulp.task('styles', function () { | |
var isProduction = args.production; | |
return gulp.src('sources/sass/**/*.scss') | |
.pipe(plumber()) | |
.pipe(sass()) | |
.pipe(gulpif(isProduction, cssnano({ | |
discardComments: {removeAll: true}, | |
browsers: [ | |
"> 1%", | |
"last 2 versions" | |
] | |
}))) | |
.pipe(gulp.dest('css')); | |
}); | |
gulp.task('scripts', function () { | |
var isProduction = args.production; | |
return gulp.src([ | |
'node_modules/jquery/dist/jquery.slim.min.js', | |
'node_modules/bootstrap/dist/js/bootstrap.js', | |
'sources/js/*.js' | |
]) | |
.pipe(concat('theme.js')) | |
.pipe(gulpif(isProduction, uglify())) | |
.pipe(gulp.dest('js')); | |
}) | |
gulp.task('images', function(){ | |
var isProduction = args.production; | |
return gulp.src('sources/img/**/*.{jpg,png,gif}') | |
.pipe(gulpif(isProduction,imagemin({ | |
optimizationLevel: 7, | |
progressive: true, | |
interlaced: true | |
}))) | |
.pipe(gulp.dest('images')) | |
}); | |
gulp.task('fonts', function () { | |
gulp.src('node_modules/font-awesome/fonts/**/*.{ttf,woff,woff2,eof,svg}') | |
.pipe(gulp.dest('fonts')); | |
}) | |
gulp.task('clean:css', function() { | |
return gulp.src('css/*.css', { read: false }) | |
.pipe(rimraf()); | |
}); | |
gulp.task('clean:images', function() { | |
return gulp.src('images/*.*', { read: false }) | |
.pipe(rimraf()); | |
}); | |
gulp.task('clean',['clean:images','clean:css']) // Limpa todas img e css | |
gulp.task('default', ['styles','images','scripts']); | |
gulp.task('watch', function () { | |
var onChange = function(event){ | |
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...'); | |
} | |
gulp.watch('sources/sass/**/*.scss', ['styles']).on('change', onChange); | |
gulp.watch('sources/js/**/*.js', ['scripts']).on('change', onChange); | |
gulp.watch('sources/img/**/*.{jpg,png,gif}', ['images']).on('change', onChange); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment