-
-
Save zerodi/c87d98efd81f3223daa2704fc7c2c827 to your computer and use it in GitHub Desktop.
Brotli compression with Angular CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const brotli = require('brotli'); | |
const zlib = require('zlib'); | |
const fs = require('fs'); | |
const brotliSettings = { | |
extension: 'br', | |
skipLarger: true, | |
mode: 1, // 0 = generic, 1 = text, 2 = font (WOFF2) | |
quality: 10, // 0 - 11, | |
lgwin: 12 // default | |
} | |
const zlibSettings = { | |
level: 9 | |
} | |
fs.readdirSync('dist/').forEach(file => { | |
if (file.endsWith('.js') || file.endsWith('.css') || file.endsWith('.html')) { | |
const fileStream = fs.readFileSync('dist/' + file); | |
const brFile = brotli.compress(fileStream, brotliSettings); | |
const gzFile = zlib.gzipSync(fileStream, zlibSettings); | |
fs.writeFileSync('dist/' + file + '.br', brFile) | |
fs.writeFileSync('dist/' + file + '.gz', gzFile) | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "my-ng-cli-app", | |
"scripts": { | |
"build-prod": "ng build --prod && node compress.js" | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment