Skip to content

Instantly share code, notes, and snippets.

@david-j-davis
Created March 26, 2017 20:52
Show Gist options
  • Save david-j-davis/1f5709d896d8b1fb7a523e7960a8587f to your computer and use it in GitHub Desktop.
Save david-j-davis/1f5709d896d8b1fb7a523e7960a8587f to your computer and use it in GitHub Desktop.
Gulpfile.js boilerplate v.2
var gulp = require('gulp'),
browserSync = require('browser-sync').create(),
sass = require('gulp-sass'),
cleanCSS = require('gulp-clean-css'),
postcss = require('gulp-postcss'),
prefix = require('autoprefixer'),
concat = require('gulp-concat'),
gulpIf = require('gulp-if'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
cache = require('gulp-cache'),
gutil = require('gulp-util'),
server = 'https://thecrnt.dev';
// Styles
gulp.task('styles', function() {
return gulp
.src('src/styles/**/*.scss')
.pipe(sass().on('error', sass.logError))
// .pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(postcss([prefix({browsers: ["> 0%"]})]))
.pipe(gulp.dest('thecrnt/'))
.pipe(browserSync.stream());
});
// Scripts
gulp.task('scripts', function() {
return gulp
.src('src/scripts/**/*.js')
.pipe(gulpIf('*.js', uglify().on('error', gutil.log)))
// .pipe(concat('scripts.js'))
.pipe(gulp.dest('thecrnt/js'));
});
// Images
gulp.task('images', function() {
return gulp
.src('src/images/**/*')
.pipe(cache(imagemin({optimizationLevel: 3, progressive: true, interlaced: true})))
.pipe(gulp.dest('thecrnt/img'));
});
// Fonts
gulp.task('fonts', function() {
return gulp
.src('src/fonts/**/*')
.pipe(cache(gulp.dest('thecrnt/fonts')))
})
// Server + Watching styles/scripts/images/html files
gulp.task('serve', [
'styles', 'scripts', 'images', 'fonts'
], function() {
browserSync.init({proxy: server});
gulp.watch('src/styles/**/*.scss', ['styles']);
gulp.watch('src/scripts/**/*.js', ['scripts']);
gulp.watch('src/images/**/*', ['images']);
gulp
.watch('thecrnt/**/*.php')
.on('change', browserSync.reload);
});
gulp.task('default', ['serve'], function() {
gulp.start('styles', 'scripts', 'images', 'fonts');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment