dispatch/client/gulpfile.js

97 lines
2.4 KiB
JavaScript
Raw Normal View History

2015-01-17 01:37:21 +00:00
var gulp = require('gulp');
var gulpif = require('gulp-if');
var minifyHTML = require('gulp-minify-html');
var minifyCSS = require('gulp-minify-css');
var autoprefixer = require('gulp-autoprefixer');
var uglify = require('gulp-uglify');
2015-02-05 00:37:34 +00:00
var gzip = require('gulp-gzip');
2015-01-17 01:37:21 +00:00
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var streamify = require('gulp-streamify');
2015-02-21 06:23:25 +00:00
var babelify = require('babelify');
2015-01-17 01:37:21 +00:00
var strictify = require('strictify');
var watchify = require('watchify');
var argv = require('yargs')
.alias('p', 'production')
.argv;
if (argv.production) {
process.env['NODE_ENV'] = 'production';
}
gulp.task('html', function() {
gulp.src('src/*.html')
2015-01-17 01:37:21 +00:00
.pipe(minifyHTML())
.pipe(gulp.dest('dist'));
2015-01-17 01:37:21 +00:00
});
gulp.task('css', function() {
gulp.src('src/css/*.css')
2015-01-17 01:37:21 +00:00
.pipe(autoprefixer())
.pipe(minifyCSS())
.pipe(gulp.dest('dist/css'));
2015-01-17 01:37:21 +00:00
});
gulp.task('js', function() {
return js(false);
});
function js(watch) {
var bundler, rebundle;
bundler = browserify('./src/js/app.js', {
debug: !argv.production,
cache: {},
packageCache: {},
fullPaths: watch
});
if (watch) {
bundler = watchify(bundler);
}
bundler
2015-02-21 06:23:25 +00:00
.transform(babelify)
2015-01-17 01:37:21 +00:00
.transform(strictify);
rebundle = function() {
var stream = bundler.bundle();
stream.on('error', console.log);
return stream
.pipe(source('bundle.js'))
.pipe(gulpif(argv.production, streamify(uglify())))
.pipe(gulp.dest('dist'));
2015-01-17 01:37:21 +00:00
};
bundler.on('time', function(time) {
console.log('JS bundle: ' + time + ' ms');
});
bundler.on('update', rebundle);
return rebundle();
}
2015-02-16 20:53:01 +00:00
gulp.task('fonts', function() {
gulp.src('src/font/*')
.pipe(gulp.dest('dist/font'));
2015-02-16 20:53:01 +00:00
});
gulp.task('gzip', ['html', 'css', 'js', 'fonts'], function() {
gulp.src('dist/**/!(*.gz)')
2015-02-05 00:37:34 +00:00
.pipe(gzip())
.pipe(gulp.dest('dist'));
2015-02-05 00:37:34 +00:00
});
gulp.task('gzip:watch', function() {
gulp.src('dist/**/*.{html,css,js}')
2015-02-05 00:37:34 +00:00
.pipe(gzip())
.pipe(gulp.dest('dist'));
2015-02-05 00:37:34 +00:00
});
2015-01-17 01:37:21 +00:00
gulp.task('watch', ['default'], function() {
gulp.watch('dist/**/*.{html,css,js}', ['gzip:watch'])
gulp.watch('src/*.html', ['html']);
gulp.watch('src/css/*.css', ['css']);
2015-01-17 01:37:21 +00:00
return js(true);
});
2015-02-16 20:53:01 +00:00
gulp.task('default', ['html', 'css', 'js', 'fonts', 'gzip']);