Skip to content

Instantly share code, notes, and snippets.

@aldo-roman
Last active November 11, 2021 13:48
Show Gist options
  • Save aldo-roman/2c437b872b4550bd3f224fec2eaaebb1 to your computer and use it in GitHub Desktop.
Save aldo-roman/2c437b872b4550bd3f224fec2eaaebb1 to your computer and use it in GitHub Desktop.
Brotli compression with Angular CLI
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)
}
})
{
"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