Skip to content

Instantly share code, notes, and snippets.

@jeffpowrs jeffpowrs/gulp_file.js
Last active Sep 4, 2015

Embed
What would you like to do?
Super Simple Gulp Starter + Static Server.
var gulp = require('gulp');
var plumber = require('gulp-plumber');
var rename = require('gulp-rename');
var autoprefixer = require('gulp-autoprefixer');
var concat = require('gulp-concat');
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var cache = require('gulp-cache');
var minifycss = require('gulp-minify-css');
var sass = require('gulp-sass');
var browserSync = require('browser-sync');
var mainBowerFiles = require('gulp-main-bower-files');
gulp.task('browser-sync', function() {
browserSync({
server: {
baseDir: "./"
}
});
});
gulp.task('bs-reload', function () {
browserSync.reload();
});
gulp.task('images', function(){
gulp.src('assets/src/images/**/*')
.pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
.pipe(gulp.dest('assets/dist/images/'));
});
gulp.task('styles', function(){
gulp.src(['assets/src/styles/**/*.scss'])
.pipe(plumber({
errorHandler: function (error) {
console.log(error.message);
this.emit('end');
}}))
.pipe(sass({includePaths: ['./node_modules']}))
.pipe(autoprefixer('last 2 versions'))
.pipe(gulp.dest('assets/dist/styles/'))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest('assets/dist/styles/'))
.pipe(browserSync.reload({stream:true}))
});
gulp.task('scripts', function(){
return gulp.src('assets/src/scripts/**/*.js')
.pipe(plumber({
errorHandler: function (error) {
console.log(error.message);
this.emit('end');
}}))
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(concat('main.js'))
.pipe(gulp.dest('assets/dist/scripts/'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest('assets/dist/scripts/'))
.pipe(browserSync.reload({stream:true}))
});
gulp.task('copy:bower', function() {
return gulp.src('./bower.json')
.pipe(mainBowerFiles())
.pipe(gulp.dest('./assets/dist/scripts/vendors/'));
});
gulp.task('copy:videos', function() {
return gulp.src('./assets/src/videos/**/*')
.pipe(gulp.dest('./assets/dist/videos/'));
});
gulp.task('copy:fonts', function() {
return gulp.src('./assets/src/fonts/**/*')
.pipe(gulp.dest('./assets/dist/fonts/'));
});
gulp.task('default', ['browser-sync'], function(){
gulp.watch("assets/src/styles/**/*.scss", ['styles']);
gulp.watch("assets/src/scripts/**/*.js", ['scripts']);
gulp.watch("./bower_components/**/*", ['copy:bower']);
gulp.watch("./assets/src/videos/**/*", ['copy:videos']);
gulp.watch("./assets/src/fonts/**/*", ['copy:fonts']);
gulp.watch("*.html", ['bs-reload']);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.