3 var gulp
= require('gulp');
4 var gzip
= require('gulp-gzip');
5 var tar
= require('gulp-tar');
6 var restoreTimestamps
= require('./gulp-restore-timestamps');
8 gulp
.task('compress:assets:files:gzip', function() {
10 .src(['output/assets/**/*.{css,js,ttf,svg,eot}', '!**/*.map'], {
12 base
: 'output/assets/'
14 .pipe(gzip({ append
: true, gzipOptions
: { level
: 9 } }))
15 .pipe(gulp
.dest('output/assets/'))
16 .pipe(restoreTimestamps());
19 // Brotli compression for text files
20 gulp
.task('compress:assets:files:brotli:text', function() {
21 if (!process
.env
.ENABLE_BROTLI_COMPRESSION
) return;
23 var brotli
= require('gulp-brotli');
25 .src(['output/assets/**/*.{css,svg,js}', '!**/*.map'], { stat
: true, base
: 'output/assets/' })
33 .pipe(gulp
.dest('output/assets/'))
34 .pipe(restoreTimestamps());
37 // Brotli compression for non-text files
38 gulp
.task('compress:assets:files:brotli:generic', function() {
39 if (!process
.env
.ENABLE_BROTLI_COMPRESSION
) return;
41 var brotli
= require('gulp-brotli');
43 .src(['output/assets/**/*.{ttf,eot}', '!**/*.map'], { stat
: true, base
: 'output/assets/' })
46 mode
: 0, // 0 = GENERIC
51 .pipe(gulp
.dest('output/assets/'))
52 .pipe(restoreTimestamps());
55 gulp
.task('compress:assets:files:brotli', [
56 'compress:assets:files:brotli:generic',
57 'compress:assets:files:brotli:text'
60 gulp
.task('compress:assets:files', ['compress:assets:files:brotli', 'compress:assets:files:gzip']);
62 gulp
.task('compress:assets:tarball', ['compress:assets:files'], function() {
64 .src(['output/assets/**', '!**/*.map'], { stat
: true })
65 .pipe(tar('assets.tar'))
66 .pipe(gzip({ append
: true, gzipOptions
: { level
: 9 } }))
67 .pipe(gulp
.dest('output'));
70 gulp
.task('compress:post-package', ['compress:assets:tarball']);