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() {
|
2015-04-22 22:44:40 +00:00
|
|
|
gulp.src('src/*.html')
|
2015-01-17 01:37:21 +00:00
|
|
|
.pipe(minifyHTML())
|
2015-04-22 22:44:40 +00:00
|
|
|
.pipe(gulp.dest('dist'));
|
2015-01-17 01:37:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('css', function() {
|
2015-04-22 22:44:40 +00:00
|
|
|
gulp.src('src/css/*.css')
|
2015-01-17 01:37:21 +00:00
|
|
|
.pipe(autoprefixer())
|
|
|
|
.pipe(minifyCSS())
|
2015-04-22 22:44:40 +00:00
|
|
|
.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())))
|
2015-04-22 22:44:40 +00:00
|
|
|
.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() {
|
2015-04-22 22:44:40 +00:00
|
|
|
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() {
|
2015-04-22 22:44:40 +00:00
|
|
|
gulp.src('dist/**/!(*.gz)')
|
2015-02-05 00:37:34 +00:00
|
|
|
.pipe(gzip())
|
2015-04-22 22:44:40 +00:00
|
|
|
.pipe(gulp.dest('dist'));
|
2015-02-05 00:37:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('gzip:watch', function() {
|
2015-04-22 22:44:40 +00:00
|
|
|
gulp.src('dist/**/*.{html,css,js}')
|
2015-02-05 00:37:34 +00:00
|
|
|
.pipe(gzip())
|
2015-04-22 22:44:40 +00:00
|
|
|
.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() {
|
2015-04-22 22:44:40 +00:00
|
|
|
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']);
|