2014-04-17 05:02:38 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var gulp = require('gulp');
|
2014-05-06 05:47:36 -07:00
|
|
|
var browserSync = require('browser-sync');
|
2014-06-06 03:59:34 -07:00
|
|
|
var pagespeed = require('psi');
|
2014-05-06 05:47:36 -07:00
|
|
|
var reload = browserSync.reload;
|
2014-04-17 05:02:38 -07:00
|
|
|
|
|
|
|
// load plugins
|
|
|
|
var $ = require('gulp-load-plugins')();
|
|
|
|
|
2014-05-07 02:33:42 -07:00
|
|
|
// hosted URL for your page
|
2014-05-18 06:40:57 -07:00
|
|
|
var hostedUrl = 'https://example.com';
|
2014-05-07 02:33:42 -07:00
|
|
|
|
2014-06-06 05:01:17 -07:00
|
|
|
// enable use of relative paths even though gulp is run in sub-directories
|
|
|
|
process.chdir(__dirname);
|
2014-06-06 04:27:56 -07:00
|
|
|
|
2014-04-17 05:02:38 -07:00
|
|
|
gulp.task('styles', function () {
|
2014-06-06 05:01:17 -07:00
|
|
|
return gulp.src('app/styles/sass/styles.scss')
|
2014-05-16 01:18:34 -07:00
|
|
|
.pipe($.rubySass({style: 'expanded', precision: 10}))
|
2014-04-17 05:02:38 -07:00
|
|
|
.pipe($.autoprefixer('last 1 version'))
|
2014-06-06 05:01:17 -07:00
|
|
|
.pipe(gulp.dest('dist/styles'))
|
2014-05-06 05:47:36 -07:00
|
|
|
.pipe(reload({stream: true}))
|
2014-04-17 05:02:38 -07:00
|
|
|
.pipe($.size());
|
|
|
|
});
|
|
|
|
|
2014-05-28 04:07:50 -07:00
|
|
|
gulp.task('jshint', function () {
|
2014-06-06 05:01:17 -07:00
|
|
|
return gulp.src('app/scripts/**/*.js')
|
2014-04-17 05:02:38 -07:00
|
|
|
.pipe($.jshint())
|
2014-05-16 01:18:34 -07:00
|
|
|
.pipe($.jshint.reporter('jshint-stylish'))
|
|
|
|
.pipe($.jshint.reporter('fail'))
|
2014-05-06 05:47:36 -07:00
|
|
|
.pipe(reload({stream: true, once: true}))
|
2014-04-17 05:02:38 -07:00
|
|
|
.pipe($.size());
|
|
|
|
});
|
|
|
|
|
2014-05-28 04:07:50 -07:00
|
|
|
gulp.task('html', ['styles'], function () {
|
2014-04-17 05:02:38 -07:00
|
|
|
var jsFilter = $.filter('**/*.js');
|
|
|
|
var cssFilter = $.filter('**/*.css');
|
|
|
|
|
2014-06-06 05:01:17 -07:00
|
|
|
return gulp.src('app/**/*.html')
|
2014-04-17 05:02:38 -07:00
|
|
|
.pipe($.useref.assets())
|
|
|
|
.pipe(jsFilter)
|
|
|
|
.pipe($.uglify())
|
|
|
|
.pipe(jsFilter.restore())
|
|
|
|
.pipe(cssFilter)
|
|
|
|
.pipe($.csso())
|
|
|
|
.pipe(cssFilter.restore())
|
|
|
|
.pipe($.useref.restore())
|
|
|
|
.pipe($.useref())
|
2014-06-06 05:01:17 -07:00
|
|
|
.pipe(gulp.dest('dist'))
|
2014-04-17 05:02:38 -07:00
|
|
|
.pipe($.size());
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('images', function () {
|
2014-06-06 05:01:17 -07:00
|
|
|
return gulp.src('app/images/**/*')
|
2014-04-17 05:02:38 -07:00
|
|
|
.pipe($.cache($.imagemin({
|
|
|
|
progressive: true,
|
|
|
|
interlaced: true
|
|
|
|
})))
|
2014-06-06 05:01:17 -07:00
|
|
|
.pipe(gulp.dest('dist/images'))
|
2014-05-06 05:47:36 -07:00
|
|
|
.pipe(reload({stream: true, once: true}))
|
2014-04-17 05:02:38 -07:00
|
|
|
.pipe($.size());
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('fonts', function () {
|
2014-05-08 11:00:30 -07:00
|
|
|
return gulp.src('**/*.{eot,svg,ttf,woff}')
|
2014-04-17 05:02:38 -07:00
|
|
|
.pipe($.flatten())
|
2014-06-06 05:01:17 -07:00
|
|
|
.pipe(gulp.dest('dist/images/icons'))
|
2014-04-17 05:02:38 -07:00
|
|
|
.pipe($.size());
|
|
|
|
});
|
|
|
|
|
2014-06-06 03:59:34 -07:00
|
|
|
gulp.task('pagespeed', function (cb) {
|
2014-06-06 06:35:58 -07:00
|
|
|
pagespeed({
|
2014-06-06 03:59:34 -07:00
|
|
|
// key: A developer API key if you have one
|
|
|
|
// See http://goo.gl/RkN0vE for more details
|
|
|
|
nokey: 'true',
|
|
|
|
url: hostedUrl,
|
|
|
|
strategy: 'mobile',
|
|
|
|
}, cb);
|
2014-05-07 02:33:42 -07:00
|
|
|
});
|
|
|
|
|
2014-04-17 05:02:38 -07:00
|
|
|
gulp.task('clean', function () {
|
2014-06-06 05:01:17 -07:00
|
|
|
return gulp.src(['.tmp', 'dist'], {read: false}).pipe($.clean());
|
2014-04-17 05:02:38 -07:00
|
|
|
});
|
|
|
|
|
2014-05-28 04:07:50 -07:00
|
|
|
gulp.task('build', ['jshint', 'html', 'images', 'fonts']);
|
2014-04-17 05:02:38 -07:00
|
|
|
|
2014-06-06 00:33:21 -07:00
|
|
|
gulp.task('default', ['clean'], function (cb) {
|
|
|
|
gulp.start('build', cb);
|
2014-04-17 05:02:38 -07:00
|
|
|
});
|
|
|
|
|
2014-05-06 05:47:36 -07:00
|
|
|
gulp.task('serve', ['styles'], function () {
|
|
|
|
browserSync.init(null, {
|
|
|
|
server: {
|
2014-06-06 05:01:17 -07:00
|
|
|
baseDir: ['app', '.tmp']
|
2014-05-06 05:47:36 -07:00
|
|
|
},
|
|
|
|
});
|
2014-04-17 05:02:38 -07:00
|
|
|
});
|
|
|
|
|
2014-05-06 05:47:36 -07:00
|
|
|
gulp.task('watch', ['serve'], function () {
|
2014-06-06 05:01:17 -07:00
|
|
|
gulp.watch(['app/*.html'], reload);
|
|
|
|
gulp.watch(['app/styles/**/*.scss', 'app/styles/**/*.css'], ['styles']);
|
|
|
|
gulp.watch('app/scripts/**/*.js', ['jshint']);
|
|
|
|
gulp.watch('app/images/**/*', ['images']);
|
2014-04-17 05:02:38 -07:00
|
|
|
});
|