Last active
November 11, 2021 13:48
-
-
Save aldo-roman/2c437b872b4550bd3f224fec2eaaebb1 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 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 | |
} | |
fs.readdirSync('dist/').forEach(file => { | |
if (file.endsWith('.js') || file.endsWith('.css') || file.endsWith('.html')) { | |
const result = brotli.compress(fs.readFileSync('dist/' + file), brotliSettings) | |
fs.writeFileSync('dist/' + file + '.br', result) | |
} | |
}) |
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