Last active
October 9, 2020 13:01
-
-
Save sturobson/8343865 to your computer and use it in GitHub Desktop.
My gulpfile.js (so far, so simple). Compiles Sass (removes erroneous _partial compilation), autoprefixes the CSS then minifies the CSS into the folder 'dist/CSS'. Uglifys JS into the foloder 'dist/JS'. Minifys SVGs using SVGO, Minifys images with imagemin. Adds gulp-size to calculate project size. Runs development and production tasks
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
// Deep Breaths // | |
////////////////// | |
// Gulp | |
var gulp = require('gulp'); | |
// Sass/CSS stuff | |
var sass = require('gulp-sass'); | |
var prefix = require('gulp-autoprefixer'); | |
var minifycss = require('gulp-minify-css'); | |
// JavaScript | |
var uglify = require('gulp-uglify'); | |
// Images | |
var svgmin = require('gulp-svgmin'); | |
var imagemin = require('gulp-imagemin'); | |
// Stats and Things | |
var size = require('gulp-size'); | |
// | |
// compile all your Sass | |
gulp.task('sass', function (){ | |
gulp.src(['./dev/sass/*.scss', '!./dev/sass/_variables.scss']) | |
.pipe(sass({ | |
includePaths: ['./dev/sass'], | |
outputStyle: 'expanded' | |
})) | |
.pipe(prefix( | |
"last 1 version", "> 1%", "ie 8", "ie 7" | |
)) | |
.pipe(gulp.dest('./dev/css')) | |
.pipe(minifycss()) | |
.pipe(gulp.dest('./prod/css')); | |
}); | |
// Uglify JS | |
gulp.task('uglify', function(){ | |
gulp.src('./dev/js/*.js') | |
.pipe(uglify()) | |
.pipe(gulp.dest('./prod/js')); | |
}); | |
// Images | |
gulp.task('svgmin', function() { | |
gulp.src('./dev/img/svg/*.svg') | |
.pipe(svgmin()) | |
.pipe(gulp.dest('./dev/img/svg')) | |
.pipe(gulp.dest('./prod/img/svg')); | |
}); | |
gulp.task('imagemin', function () { | |
gulp.src('./dev/img/**/*') | |
.pipe(imagemin()) | |
.pipe(gulp.dest('./dev/img')) | |
.pipe(gulp.dest('./prod/img')); | |
}); | |
// Stats and Things | |
gulp.task('stats', function () { | |
gulp.src('./prod/**/*') | |
.pipe(size()) | |
.pipe(gulp.dest('./prod')); | |
}); | |
// | |
gulp.task('default', function(){ | |
// watch me getting Sassy | |
gulp.watch("./dev/sass/**/*.scss", function(event){ | |
gulp.run('sass'); | |
}); | |
// make my JavaScript ugly | |
gulp.watch("./dev/js/**/*.js", function(event){ | |
gulp.run('uglify'); | |
}); | |
// images | |
gulp.watch("./dev/img/**/*", function(event){ | |
gulp.run('imagemin'); | |
gulp.run('svgmin'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Me laikes