From 1e7c762e4176e6b1213665a63c7188f0dfbb9d8b Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Mon, 24 Jun 2024 15:31:42 -0600 Subject: [PATCH] compress fonts and add them to UI bundle --- ui/gulp.d/tasks/pack.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ui/gulp.d/tasks/pack.js b/ui/gulp.d/tasks/pack.js index 440482f..3c94166 100644 --- a/ui/gulp.d/tasks/pack.js +++ b/ui/gulp.d/tasks/pack.js @@ -1,11 +1,33 @@ 'use strict' const ospath = require('node:path') +const { Transform } = require('node:stream') +const map = (transform) => new Transform({ objectMode: true, transform }) const vfs = require('vinyl-fs') const zip = require('@vscode/gulp-vinyl-zip') +const zlib = require('node:zlib') module.exports = (src, dest, bundleName, onFinish) => () => vfs .src('**/*', { base: src, cwd: src, dot: true }) + .pipe( + map(function (file, _, next) { + if (file.relative.startsWith('font/')) { + zlib.gzip(file.contents, (gzipErr, compressedContents) => { + if (gzipErr) return next(gzipErr) + this.push( + new file.constructor({ + path: file.relative + '.gz', + contents: compressedContents, + stat: file.stat, + }) + ) + next(null, file) + }) + } else { + next(null, file) + } + }) + ) .pipe(zip.dest(ospath.join(dest, `${bundleName}-bundle.zip`))) .on('finish', () => onFinish && onFinish(ospath.resolve(dest, `${bundleName}-bundle.zip`)))