material-design-lite/gulpfile.js

105 lines
2.8 KiB
JavaScript
Raw Normal View History

2014-04-17 05:02:38 -07:00
'use strict';
var gulp = require('gulp');
var browserSync = require('browser-sync');
2014-06-06 03:59:34 -07:00
var pagespeed = require('psi');
var reload = browserSync.reload;
2014-04-17 05:02:38 -07:00
// load plugins
var $ = require('gulp-load-plugins')();
// hosted URL for your page
var hostedUrl = 'https://example.com';
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-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')
.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'))
.pipe(reload({stream: true}))
2014-04-17 05:02:38 -07:00
.pipe($.size());
});
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())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.jshint.reporter('fail'))
.pipe(reload({stream: true, once: true}))
2014-04-17 05:02:38 -07:00
.pipe($.size());
});
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'))
.pipe(reload({stream: true, once: true}))
2014-04-17 05:02:38 -07:00
.pipe($.size());
});
gulp.task('fonts', function () {
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-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
});
gulp.task('build', ['jshint', 'html', 'images', 'fonts']);
2014-04-17 05:02:38 -07:00
gulp.task('default', ['clean'], function (cb) {
gulp.start('build', cb);
2014-04-17 05:02:38 -07:00
});
gulp.task('serve', ['styles'], function () {
browserSync.init(null, {
server: {
2014-06-06 05:01:17 -07:00
baseDir: ['app', '.tmp']
},
});
2014-04-17 05:02:38 -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
});