Last active
September 16, 2017 10:43
-
-
Save Titoratus/1dade3ff3027e79f5370f0a67b1522db to your computer and use it in GitHub Desktop.
gulpfile.js
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'), | |
sass = require('gulp-sass'), | |
browserSync = require('browser-sync'), | |
uglify = require('gulp-uglifyjs'), | |
concat = require('gulp-concat'), | |
rename = require('gulp-rename'), | |
cssnano = require('gulp-cssnano'), | |
del = require('del'), | |
imagemin = require('gulp-imagemin'), | |
pngquant = reuqire('imagemin-pngquant'), | |
cache = require('gulp-cache'), | |
autoprefixer = require('gulp-autoprefixer'); | |
gulp.task('sass', function(){ | |
return gulp.src('app/sass/**/*.sass') | |
.pipe(sass()) | |
.pipe(autoprefixer(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], {cascade: true})) | |
.pipe(gulp.dest('app/css')) | |
.pipe(browserSync.reload({stream: true})) | |
}); | |
gulp.task('browser-sync', function(){ | |
browserSync({ | |
server: { | |
baseDir: 'app' | |
}, | |
notify: false | |
}); | |
}); | |
gulp.task('scripts', function(){ | |
return gulp.src([ | |
'app/libs/jquery/dist/jquery.min.js', | |
'app/libs/owl.carousel/dist/owl.carousel.min.js' | |
]) | |
.pipe(concat('libs.min.js')) | |
.pipe(uglify()) | |
.pipe(gulp.dest('app/js')) | |
}); | |
gulp.task('css-libs', ['sass'], function(){ | |
return gulp.src('app/css/libs.css') | |
.pipe(cssnano()) | |
.pipe(rename({suffix: '.min'})) | |
.pipe(gulp.dest('app/css')) | |
}); | |
gulp.task('watch', ['css-libs', 'browser-sync', 'scripts'], function(){ | |
gulp.watch('app/sass/**/*.sass', ['sass']); | |
gulp.watch('app/*.html', browserSync.reload); | |
gulp.watch('app/js/**/*.js', browserSync.reload) | |
}); | |
gulp.task('img', function(){ | |
return gulp.src('app/img/**/*') | |
.pipe(cache(imagemin({ | |
interplaced: true, | |
progressive: true, | |
svgoPlugins: [{removeViewBox: false}], | |
use: [pngquant()] | |
}))) | |
.pipe(gulp.dest('dist/img')); | |
}); | |
gulp.task('clean', function(){ | |
return del.sync('dist'); | |
}); | |
gulp.task('build', ['clean', 'img', 'css-libs', 'scripts'], function(){ | |
var buildCss = gulp.src([ | |
'app/css/main.css', | |
'app/css/libs.min.css' | |
]) | |
.pipe(gulp.dest('dist/css')) | |
var buildFonts = gulp.src('app/fonts/**/*') | |
.pipe(gulp.dest('dist/fonts')) | |
var buildJs = gulp.src('app/js/**/*') | |
.pipe(gulp.dest('dist/js')) | |
var buildHTML = gulp.src('app/*.html') | |
.pipe('dist'); | |
}); | |
gulp.task('default', ['watch']); | |
gulp.task('clear', function(){ | |
return cache.clearAll(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment