Merge branch '2836-only-clean-gitter.im-orphaned-rooms' into 'develop'
[gitter.git] / build-scripts / gulpfile-compress.js
blob7209e8503c7ee7d8519b1e4678f3d455160aee8b
1 'use strict';
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() {
9   return gulp
10     .src(['output/assets/**/*.{css,js,ttf,svg,eot}', '!**/*.map'], {
11       stat: true,
12       base: 'output/assets/'
13     })
14     .pipe(gzip({ append: true, gzipOptions: { level: 9 } }))
15     .pipe(gulp.dest('output/assets/'))
16     .pipe(restoreTimestamps());
17 });
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');
24   return gulp
25     .src(['output/assets/**/*.{css,svg,js}', '!**/*.map'], { stat: true, base: 'output/assets/' })
26     .pipe(
27       brotli.compress({
28         mode: 1, // 1 = TEXT
29         extension: 'br',
30         quality: 11
31       })
32     )
33     .pipe(gulp.dest('output/assets/'))
34     .pipe(restoreTimestamps());
35 });
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');
42   return gulp
43     .src(['output/assets/**/*.{ttf,eot}', '!**/*.map'], { stat: true, base: 'output/assets/' })
44     .pipe(
45       brotli.compress({
46         mode: 0, // 0 = GENERIC
47         extension: 'br',
48         quality: 11
49       })
50     )
51     .pipe(gulp.dest('output/assets/'))
52     .pipe(restoreTimestamps());
53 });
55 gulp.task('compress:assets:files:brotli', [
56   'compress:assets:files:brotli:generic',
57   'compress:assets:files:brotli:text'
58 ]);
60 gulp.task('compress:assets:files', ['compress:assets:files:brotli', 'compress:assets:files:gzip']);
62 gulp.task('compress:assets:tarball', ['compress:assets:files'], function() {
63   return gulp
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'));
68 });
70 gulp.task('compress:post-package', ['compress:assets:tarball']);