Use gulp-replace to rewrite JS and CSS paths during gzip task.

`index.html.gz` now links properly to gzipped resources allowing
them to be distributed unmodified and without the uncompressed
resources.

Change-Id: I253f5207de5b13a105dfb8ddd226d7da6ba2b34b
This commit is contained in:
Tim Buckley 2015-09-25 17:55:33 -06:00
parent 8952ea2e5e
commit 6ae7d8ace1
4 changed files with 13 additions and 10 deletions

View File

@ -39,13 +39,7 @@ distribution. Note that all files are not required:
- Core files (:code:`index.html`, :code:`js/main.js`, :code:`css/main.css`):
required unless gzipped versions are used.
- Gzipped versions of core files (:code:`*.gz`): not required, but preferred.
Use instead of plain core files.
- Note that filenames must have the :code:`.gz` extension removed as links are
not currently rewritten to reflect the extension added during the gzip
process. TODO: investigate use of
`gulp-rebase <https://github.com/tunderdomb/rebase>`_ to avoid this.
Use instead of plain core files to save on disk usage and bandwidth.
- Source maps (:code:`js/main.js.map`, :code:`js/main.js.map.gz`): only required
for debugging purposes.

View File

@ -37,6 +37,7 @@ module.exports = {
'gzip': {
'src': 'build/**/*.{html,xml,json,css,js,js.map}',
'rewrite': '**/*.html',
'dest': 'build/',
'options': {}
},

View File

@ -1,12 +1,18 @@
'use strict';
var gulp = require('gulp');
var gzip = require('gulp-gzip');
var config = require('../config');
var gulp = require('gulp');
var gzip = require('gulp-gzip');
var config = require('../config');
var filter = require('gulp-filter');
var replace = require('gulp-replace');
gulp.task('gzip', function() {
var rewriteFilter = filter(config.gzip.rewrite, { restore: true });
return gulp.src(config.gzip.src)
.pipe(rewriteFilter)
.pipe(replace(/"((?:css|js)\/.*\.(?:css|js))"/g, '"$1.gz"'))
.pipe(rewriteFilter.restore)
.pipe(gzip(config.gzip.options))
.pipe(gulp.dest(config.gzip.dest));

View File

@ -26,6 +26,7 @@
"gulp-angular-templatecache": "^1.3.0",
"gulp-autoprefixer": "^2.0.0",
"gulp-changed": "^1.0.0",
"gulp-filter": "^3.0.1",
"gulp-gzip": "^0.0.8",
"gulp-if": "^1.2.5",
"gulp-imagemin": "^1.1.0",
@ -34,6 +35,7 @@
"gulp-notify": "^2.0.0",
"gulp-protractor": "0.0.11",
"gulp-rename": "^1.2.0",
"gulp-replace": "^0.5.4",
"gulp-sass": "^1.3.3",
"gulp-sourcemaps": "^1.3.0",
"gulp-streamify": "0.0.5",