Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
'use strict';
// generated on 2014-04-26 using generator-gulp-bootstrap 0.0.1
var gulp = require('gulp');
var browserSync = require("browser-sync");
// load plugins
var $ = require('gulp-load-plugins')();
gulp.task('styles', function () {
return gulp.src('app/styles/main.scss')
.pipe($.plumber(function(error) {
$.util.log($.util.colors.red(error.message));
this.emit('end');
}))
.pipe($.sass())
.pipe($.autoprefixer('last 1 version'))
.pipe(gulp.dest('app/styles'))
.pipe($.size())
.pipe(browserSync.reload({stream:true}));
});
gulp.task('scripts', function () {
return gulp.src('app/scripts/**/*.js')
.pipe($.jshint())
.pipe($.jshint.reporter($.jshintStylish))
.pipe($.size())
.pipe(browserSync.reload({stream:true}));
});
gulp.task('html', ['styles', 'scripts'], function () {
var jsFilter = $.filter('**/*.js');
var cssFilter = $.filter('**/*.css');
return gulp.src('app/*.html')
.pipe($.useref.assets())
.pipe(jsFilter)
.pipe($.uglify())
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe($.csso())
.pipe(cssFilter.restore())
.pipe($.useref.restore())
.pipe($.useref())
.pipe(gulp.dest('dist'))
.pipe($.size())
.pipe(browserSync.reload({stream:true}));
});
gulp.task('images', function () {
return gulp.src('app/images/**/*')
.pipe($.cache($.imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
})))
.pipe(gulp.dest('dist/images'))
.pipe($.size())
.pipe(browserSync.reload({stream:true}));
});
gulp.task('fonts', function () {
return $.bowerFiles()
.pipe($.filter('**/*.{eot,svg,ttf,woff}'))
.pipe($.flatten())
.pipe(gulp.dest('dist/fonts'))
.pipe($.size())
.pipe(browserSync.reload({stream:true}));
});
gulp.task('clean', function () {
return gulp.src(['app/styles/main.css', 'dist'], { read: false }).pipe($.clean());
});
gulp.task('build', ['html', 'images', 'fonts']);
gulp.task('default', ['clean'], function () {
gulp.start('build');
});
gulp.task('browser-sync', function() {
var browserSync = require('browser-sync');
browserSync.init(null, {
server: {
baseDir: "app"
},
// Append '.xip.io' to the hostname. (eg: http://192.168.0.4.xip.io:3002)
hostnameSuffix: ".xip.io"
});
});
gulp.task('serve', ['browser-sync', 'styles']);
// inject bower components
gulp.task('wiredep', function () {
var wiredep = require('wiredep').stream;
gulp.src('app/styles/*.scss')
.pipe(wiredep({
directory: 'app/bower_components'
}))
.pipe(gulp.dest('app/styles'));
gulp.src('app/*.html')
.pipe(wiredep({
directory: 'app/bower_components',
exclude: ['bootstrap-sass-official']
}))
.pipe(gulp.dest('app'));
});
gulp.task('watch', ['browser-sync', 'serve'], function () {
// watch for changes
gulp.watch([
'app/*.html',
]).on('change', function () {
browserSync.reload();
});
gulp.watch('app/styles/**/*.scss', ['styles']);
gulp.watch('app/scripts/**/*.js', ['scripts']);
gulp.watch('app/images/**/*', ['images']);
gulp.watch('bower.json', ['wiredep']);
});
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.